From 214b53175781271464e55728f165cafe2dc9c2cd Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 8 Sep 2025 09:47:34 +0100 Subject: [PATCH] Add exam scores user template with dynamic answer display and feedback --- generic/views.py | 6 +- shorts/templates/shorts/exam_scores_user.html | 103 ++++++++++++++++++ 2 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 shorts/templates/shorts/exam_scores_user.html diff --git a/generic/views.py b/generic/views.py index 4f344b60..abddc0aa 100644 --- a/generic/views.py +++ b/generic/views.py @@ -146,6 +146,9 @@ import plotly.express as px from django.db.models import Prefetch +from loguru import logger + + class RedirectMixin: def get_success_url(self) -> str: if "redirect" in self.request.GET: @@ -2329,6 +2332,7 @@ class ExamViews(View, LoginRequiredMixin): if not exam.publish_results and not view_all_results: correct_answer = "*****" answer_score = 0 + logger.debug(f"{ans=} {answer_score=} {correct_answer=}") answers.append(ans) answers_marks.append(answer_score) @@ -2345,7 +2349,7 @@ class ExamViews(View, LoginRequiredMixin): case "physics": total_score = sum(sum(i) for i in answers_marks) case _: - if "unmarked" in answers_marks: + if "unmarked" in answers_marks or None in answers_marks: answered = [i for i in answers_marks if type(i) == int] total_score = sum(answered) unmarked_number = len(answers_marks) - len(answered) diff --git a/shorts/templates/shorts/exam_scores_user.html b/shorts/templates/shorts/exam_scores_user.html new file mode 100644 index 00000000..e1760c5f --- /dev/null +++ b/shorts/templates/shorts/exam_scores_user.html @@ -0,0 +1,103 @@ +{% extends 'base.html' %} + +{% block content %} +
+
HIDE/SHOW
+
+ Question 1 +
+
+ +
+
+ Answers: +
+
+
+
+
+ {% include 'user_score_header.html' %} + + {% include 'user_scores_footer.html' %} +
+{% endblock %} +{% block js %} + +{% endblock %} + + +{% block css %} + +{% endblock css %} + \ No newline at end of file