{% extends "base.html" %}

{% block content %}

    <h1>Elections ({{ object_list|length }})</h1>

    {% for year, year_list in group_list %}
        <h3>{{ year }} ({{ year_list|length }})</h3>

        <table class="table table-sm">
            <thead>
                <tr>
                    <th>Date</th>
                    <th>Type</th>
                    <th>Ballot measures</th>
                    <th>Candidate contests</th>
                    <th>Identifiers</th>
                    <th>Sources</th>
                </tr>
            </thead>
            <tbody>
            {% for obj in year_list %}
            <tr>
                <td style="width: 150px;">
                    <a href="{% url 'election_detail' obj.id %}">
                        {{ obj.date|date:"N j" }}
                    </a>
                </td>
                <td style="width: 150px;">
                    {% for type in obj.election_types %}
                        {{ type|lower|title }}{% if not forloop.last %},{% endif %}
                    {% endfor %}
                </td>
                <td style="width: 150px;">{{ obj.ballotmeasurecontests.count }}</td>
                <td style="width: 200px;">{{ obj.candidatecontests.count }}</td>
                <td style="width: 150px;">
                    {% for obj in obj.identifiers.all %}
                        {{ obj.identifier }}{% if not forloop.last %},{% endif %}
                    {% endfor %}
                </td>
                <td style="width: 150px;">
                    {% for obj in obj.sources.all %}
                        <a href="{{ obj.url }}">{{ forloop.counter }}{% if not forloop.last %},{% endif %}</a>
                    {% endfor %}
                </td>
            </tr>
            {% endfor %}
            </tbody>
        </table>
    {% endfor %}

{% endblock %}
