From eaf8a38fe271f50014d0bbab0d8258e992d2e1f4 Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 10 Nov 2025 12:41:38 +0000 Subject: [PATCH] Enhance exam review display to show correct answers and update result color descriptions for clarity --- .../templates/generic/exam_review_start.html | 5 +++- generic/views.py | 26 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/generic/templates/generic/exam_review_start.html b/generic/templates/generic/exam_review_start.html index efff5964..944029c0 100644 --- a/generic/templates/generic/exam_review_start.html +++ b/generic/templates/generic/exam_review_start.html @@ -9,7 +9,7 @@ -

Colour indicates likely attention needed: green (good), yellow (check), red (needs attention). Hover for details.

+

Colour indicates question results (for exam): green (good), yellow (check), red (needs attention). Hover for details.

{% for qs in question_summaries %} @@ -22,6 +22,9 @@

Responses: {{ qs.total_responses }}{% if qs.top_answer %} — top: "{{ qs.top_answer }}"{% endif %}

+ {% if qs.correct_answer %} +

Correct: {{ qs.correct_answer|safe }}

+ {% endif %}
Review diff --git a/generic/views.py b/generic/views.py index ecefae02..f865eb9b 100644 --- a/generic/views.py +++ b/generic/views.py @@ -1291,6 +1291,31 @@ class ExamViews(View, LoginRequiredMixin): pct_val = pcts.get(k, 0.0) if isinstance(pcts, dict) else 0.0 breakdown.append((k, v, pct_val)) + # Determine the canonical correct answer representation for display. + correct_answer = None + try: + if self.app_name == "sbas": + correct_answer = q.get_correct_answer() + elif self.app_name == "physics": + correct_answer = q.get_answers() + else: + # get_primary_answer is used elsewhere as the generic primary answer + try: + correct_answer = q.get_primary_answer() + except Exception: + correct_answer = getattr(q, "best_answer", None) + + # Normalise iterable answers into a readable string + if isinstance(correct_answer, (list, tuple)): + try: + correct_answer = ", ".join([str(x) for x in correct_answer]) + except Exception: + correct_answer = str(correct_answer) + elif correct_answer is not None: + correct_answer = str(correct_answer) + except Exception: + correct_answer = None + question_summaries.append( { "question": q, @@ -1299,6 +1324,7 @@ class ExamViews(View, LoginRequiredMixin): "counts": counts, "pcts": pcts, "correct_pct": correct_pct, + "correct_answer": correct_answer, "answered_pct": answered_pct, "colour": colour, "top_answer": top_answer,