Refactor exam collections list to use Bootstrap cards for improved layout and add total exam count display

This commit is contained in:
Ross
2025-11-07 22:13:09 +00:00
parent bd0859cce0
commit 00a675b715
@@ -2,15 +2,60 @@
{% block content %}
<h1>Exam Collections</h1>
<ul class="collections">
{% for collection in object_list %}
<li class="collection"><a href="{% url 'generic:examcollection_detail' collection.pk %}">{{ collection.name }} [{{ collection.date}}] (Authors: {{ collection.get_authors }})</a></li>
{% empty %}
<li>No exam collections yet.</li>
{% endfor %}
</ul>
<h1 class="mb-4">Exam Collections</h1>
{% if object_list %}
<div class="row row-cols-1 row-cols-md-2 row-cols-lg-3 g-3">
{% for collection in object_list %}
<div class="col">
<div class="card h-100 shadow-sm">
<div class="card-body d-flex flex-column">
<div class="mb-2">
<a class="stretched-link h5 mb-0 d-block" href="{% url 'generic:examcollection_detail' collection.pk %}">{{ collection.name }}</a>
{% if collection.date %}
<div class="text-muted small">Date: {{ collection.date }}</div>
{% endif %}
</div>
<div class="mb-2">
<small class="text-muted">Authors: {{ collection.get_authors }}</small>
</div>
<div class="mb-3">
{% comment %} Show archive state and counts per exam type {% endcomment %}
{% if collection.archive %}
<span class="badge bg-secondary" title="Archived">Archived</span>
{% endif %}
{# Total exams count (sum of known related exam sets) #}
{% with a=collection.anatomy_exams.count l=collection.longs_exams.count p=collection.physics_exams.count r=collection.rapids_exams.count s=collection.sbas_exams.count %}
{% with total=a|add:l|add:p|add:r|add:s %}
<span class="badge bg-info text-dark ms-1" title="Total exams">{{ total }} exams</span>
{% endwith %}
{# Per-type badges (only show non-zero) #}
{% if a %}<span class="badge bg-primary ms-1">Anatomy {{ a }}</span>{% endif %}
{% if l %}<span class="badge bg-primary ms-1">Longs {{ l }}</span>{% endif %}
{% if p %}<span class="badge bg-primary ms-1">Physics {{ p }}</span>{% endif %}
{% if r %}<span class="badge bg-primary ms-1">Rapids {{ r }}</span>{% endif %}
{% if s %}<span class="badge bg-primary ms-1">SBAs {{ s }}</span>{% endif %}
{% endwith %}
</div>
<div class="mt-auto d-flex gap-2">
<a class="btn btn-sm btn-outline-primary" href="{% url 'generic:examcollection_detail' collection.pk %}">View</a>
{% if can_edit %}
<a class="btn btn-sm btn-outline-secondary" href="{% url 'generic:examcollection_edit' collection.pk %}">Edit</a>
<a class="btn btn-sm btn-outline-warning" href="{% url 'generic:examcollection_clone' collection.pk %}">Clone</a>
{% endif %}
</div>
</div>
</div>
</div>
{% endfor %}
</div>
{% else %}
<div class="alert alert-info">No exam collections yet.</div>
{% endif %}
{% endblock %}