From 486a897e6456c4b7eabf568cea1649cf3cca6762 Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 10 Nov 2025 11:00:54 +0000 Subject: [PATCH] Refactor DICOM image div indentation for improved readability in exam review template --- .../exam_review_question_fragment.html | 6 +++--- anatomy/views.py | 21 ++++++++++++++++--- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/anatomy/templates/anatomy/partials/exam_review_question_fragment.html b/anatomy/templates/anatomy/partials/exam_review_question_fragment.html index e5309f47..99566d2c 100644 --- a/anatomy/templates/anatomy/partials/exam_review_question_fragment.html +++ b/anatomy/templates/anatomy/partials/exam_review_question_fragment.html @@ -1,9 +1,9 @@

{{ question.question_type }}

-
-
+
+

View full question details diff --git a/anatomy/views.py b/anatomy/views.py index fdd16661..146c1016 100644 --- a/anatomy/views.py +++ b/anatomy/views.py @@ -347,7 +347,15 @@ def exam_review_question_summary(request, pk: int, q_index: int): pass # simpler: compute via values and normalise unmarked -> 'empty' - score_counts = {str(row["score"]) if row["score"] is not None else "empty": row["count"] for row in ua_qs.values("score").annotate(count=Count("id"))} + def _norm_score_key(v): + # Treat None or empty-string scores as the 'empty' bucket + if v is None: + return "empty" + if isinstance(v, str) and v.strip() == "": + return "empty" + return str(v) + + score_counts = {_norm_score_key(row["score"]): row["count"] for row in ua_qs.values("score").annotate(count=Count("id"))} # top submitted answers (by answer_compare) with dominant score per answer # First, get counts grouped by answer_compare and score @@ -357,7 +365,7 @@ def exam_review_question_summary(request, pk: int, q_index: int): answer_map = {} for row in grouped: ans = row["answer_compare"] - sc = str(row["score"]) if row["score"] is not None else "empty" + sc = _norm_score_key(row["score"]) cnt = row["count"] if ans not in answer_map: answer_map[ans] = {"total": 0, "score_counts": {}} @@ -372,7 +380,14 @@ def exam_review_question_summary(request, pk: int, q_index: int): # sort by (count desc, score desc) where 'empty' maps to -1 def score_key(item): s, c = item - s_val = -1 if s == "empty" else int(s) + # Map 'empty' (or any non-numeric key) to a low value so numeric scores win ties + if s == "empty": + s_val = -1 + else: + try: + s_val = int(s) + except Exception: + s_val = -1 return (c, s_val) dominant = max(score_counts.items(), key=score_key)[0]