From 06ea87be14e7a6b586f53dfddee6dceb02153d83 Mon Sep 17 00:00:00 2001 From: Ross Date: Tue, 11 Nov 2025 21:26:05 +0000 Subject: [PATCH] Add shorts exam count to collection annotations and update display logic --- .../generic/examcollection_list.html | 3 +- generic/views.py | 34 +++++++++++++++---- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/generic/templates/generic/examcollection_list.html b/generic/templates/generic/examcollection_list.html index cd343552..12fe7e8d 100755 --- a/generic/templates/generic/examcollection_list.html +++ b/generic/templates/generic/examcollection_list.html @@ -38,12 +38,13 @@ {# Use annotated counts provided by the view to avoid per-card COUNT queries #} {{ collection.total_count }} exams {# Per-type badges (only show non-zero) #} - {% with a=collection.anatomy_count l=collection.longs_count p=collection.physics_count r=collection.rapids_count s=collection.sbas_count %} + {% with a=collection.anatomy_count l=collection.longs_count p=collection.physics_count r=collection.rapids_count s=collection.sbas_count sh=collection.shorts_count %} {% if a %}Anatomy {{ a }}{% endif %} {% if l %}Longs {{ l }}{% endif %} {% if p %}Physics {{ p }}{% endif %} {% if r %}Rapids {{ r }}{% endif %} {% if s %}SBAs {{ s }}{% endif %} + {% if sh %}Shorts {{ sh }}{% endif %} {% endwith %} diff --git a/generic/views.py b/generic/views.py index d0a672d7..89df7d14 100644 --- a/generic/views.py +++ b/generic/views.py @@ -5350,23 +5350,44 @@ class ExamCollectionList(ListView): base_qs = base_qs.filter(archive=False) # Build annotation kwargs dynamically so counts respect the show_archived toggle. + # Count exams regardless of exam_mode; include archived depending on the toggle. if show_archived: - # include archived exams in counts + # include archived exams in counts (count all exams for each app) counts = { "anatomy_count": Count("anatomy_exams"), "longs_count": Count("longs_exams"), "physics_count": Count("physics_exams"), "rapids_count": Count("rapids_exams"), "sbas_count": Count("sbas_exams"), + "shorts_count": Count("shorts_exams"), } else: # only count non-archived exams counts = { - "anatomy_count": Count("anatomy_exams", filter=Q(anatomy_exams__archive=False)), - "longs_count": Count("longs_exams", filter=Q(longs_exams__archive=False)), - "physics_count": Count("physics_exams", filter=Q(physics_exams__archive=False)), - "rapids_count": Count("rapids_exams", filter=Q(rapids_exams__archive=False)), - "sbas_count": Count("sbas_exams", filter=Q(sbas_exams__archive=False)), + "anatomy_count": Count( + "anatomy_exams", + filter=Q(anatomy_exams__archive=False), + ), + "longs_count": Count( + "longs_exams", + filter=Q(longs_exams__archive=False), + ), + "physics_count": Count( + "physics_exams", + filter=Q(physics_exams__archive=False), + ), + "rapids_count": Count( + "rapids_exams", + filter=Q(rapids_exams__archive=False), + ), + "sbas_count": Count( + "sbas_exams", + filter=Q(sbas_exams__archive=False), + ), + "shorts_count": Count( + "shorts_exams", + filter=Q(shorts_exams__archive=False), + ), } qs = ( @@ -5378,6 +5399,7 @@ class ExamCollectionList(ListView): + F("physics_count") + F("rapids_count") + F("sbas_count") + + F("shorts_count") ) .prefetch_related("author") .order_by("name")