Enhance exam review display to show correct answers and update result color descriptions for clarity

This commit is contained in:
Ross
2025-11-10 12:41:38 +00:00
parent 744f2c7600
commit eaf8a38fe2
2 changed files with 30 additions and 1 deletions
@@ -9,7 +9,7 @@
</div>
</div>
<p class="text-muted small">Colour indicates likely attention needed: green (good), yellow (check), red (needs attention). Hover for details.</p>
<p class="text-muted small">Colour indicates question results (for exam): green (good), yellow (check), red (needs attention). Hover for details.</p>
<div class="row">
{% for qs in question_summaries %}
@@ -22,6 +22,9 @@
</div>
<p class="card-text small text-muted mb-2">Responses: {{ qs.total_responses }}{% if qs.top_answer %} — top: "{{ qs.top_answer }}"{% endif %}</p>
{% if qs.correct_answer %}
<p class="card-text small mb-2"><strong>Correct:</strong> <span class="text-success">{{ qs.correct_answer|safe }}</span></p>
{% endif %}
<div class="d-flex gap-2">
<a class="btn btn-sm btn-outline-primary" href="{% url app_name|add:':exam_review_question' exam.pk qs.q_index %}">Review</a>
+26
View File
@@ -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,