{% comment %} For displaying a list of objects in a chart. Expects: * object_list - A list/QuerySet of objects, each having a `chart_position` attribue. OR, each item could be a list of objects, again with `chart_position` attributes (presumably each would have the same `chart_position` value). * score_attr - The name of the attribute on each object that contains the score for the chart. e.g. 'num_visits' * name_attr - The name of the attribute on each object to be used for its display value. Default is 'name'. * in_card - Boolean, default is False. Is this displayed within a .card element? * use_cite - If True, then wrap the name in tags. Default: False. {% endcomment %} {% load spectator_core %} {% for obj in object_list %}
  • {% spaceless %} {% with use_cite|default_if_none:False as use_cite %} {% if obj|length == 0 %} {# A single object. #} {% if use_cite %}{% endif %}{% if name_attr %}{{ obj|get_attr:name_attr }}{% else %}{{ obj.name }}{% endif %}{% if use_cite %}{% endif %} {% else %} {# A list of objects. #} {% for subobj in obj %} {% if forloop.first %}{% else %}{% if forloop.last %} and {% else %}, {% endif %}{% endif %} {% if use_cite %}{% endif %}{% if name_attr %}{{ subobj|get_attr:name_attr }}{% else %}{{ subobj.name }}{% endif %}{% if use_cite %}{% endif %} {% endfor %} {% endif %} {% endwith %} {% endspaceless %} ({% if obj|length == 0 %}{{ obj|get_attr:score_attr }}{% else %}{{ obj.0|get_attr:score_attr }}{% endif %})
  • {% endfor %}