Refactor DICOM image div indentation for improved readability in exam review template

This commit is contained in:
Ross
2025-11-10 11:00:54 +00:00
parent fee123741d
commit 486a897e64
2 changed files with 21 additions and 6 deletions
@@ -1,9 +1,9 @@
<div class="card mb-3"> <div class="card mb-3">
<div class="card-body"> <div class="card-body">
<p class="lead">{{ question.question_type }}</p> <p class="lead">{{ question.question_type }}</p>
<div id="dicom-image" class="dicom-image" data-url="{{ question.get_image_url }}" <div id="dicom-image" class="dicom-image" data-url="{{ question.get_image_url }}"
data-annotations='{{question.image_annotations}}' data-edit_annotation=true> data-annotations='{{question.image_annotations}}' data-edit_annotation=true>
</div> </div>
<p> <p>
<a class="btn btn-sm btn-outline-secondary" href="{% url app_name|add:':question_detail' question.pk %}" target="_blank">View full question details</a> <a class="btn btn-sm btn-outline-secondary" href="{% url app_name|add:':question_detail' question.pk %}" target="_blank">View full question details</a>
+18 -3
View File
@@ -347,7 +347,15 @@ def exam_review_question_summary(request, pk: int, q_index: int):
pass pass
# simpler: compute via values and normalise unmarked -> 'empty' # 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 # top submitted answers (by answer_compare) with dominant score per answer
# First, get counts grouped by answer_compare and score # 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 = {} answer_map = {}
for row in grouped: for row in grouped:
ans = row["answer_compare"] 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"] cnt = row["count"]
if ans not in answer_map: if ans not in answer_map:
answer_map[ans] = {"total": 0, "score_counts": {}} 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 # sort by (count desc, score desc) where 'empty' maps to -1
def score_key(item): def score_key(item):
s, c = 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) return (c, s_val)
dominant = max(score_counts.items(), key=score_key)[0] dominant = max(score_counts.items(), key=score_key)[0]