Add shorts exam count to collection annotations and update display logic
This commit is contained in:
@@ -38,12 +38,13 @@
|
||||
{# Use annotated counts provided by the view to avoid per-card COUNT queries #}
|
||||
<span class="badge bg-info text-dark ms-1" title="Total exams">{{ collection.total_count }} exams</span>
|
||||
{# 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 %}<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 %}
|
||||
{% if sh %}<span class="badge bg-primary ms-1">Shorts {{ sh }}</span>{% endif %}
|
||||
{% endwith %}
|
||||
</div>
|
||||
|
||||
|
||||
+28
-6
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user