test updating view

This commit is contained in:
Ross
2025-11-08 21:48:27 +00:00
parent 4d830bb8e7
commit 1a45f11fc2
+15 -7
View File
@@ -2816,16 +2816,22 @@ class ExamViews(View, LoginRequiredMixin):
if self.app_name in ("physics", "sbas", "longs", "shorts"):
cached_scores = False
questions = exam.get_questions()
questions_qs = exam.get_questions()
else:
questions = exam.get_questions().prefetch_related("answers")
questions_qs = exam.get_questions().prefetch_related("answers")
# We could prefect the UserAnswers.answers here (if we didn't cache them)
cid_user_answers = self.UserAnswer.objects.select_related("question").filter(
question__in=questions, exam__id=pk
# Materialize questions into a list so we can index and build a question->index map
questions = list(questions_qs)
question_index_map = {q: i for i, q in enumerate(questions)}
# We could prefetch the UserAnswers.answers here (if we didn't cache them)
# Also select_related the user to avoid per-answer user lookups in the loop
cid_user_answers = (
self.UserAnswer.objects.select_related("question", "user")
.filter(question__in=questions, exam__id=pk)
)
question_number = questions.count()
question_number = len(questions)
cids = set()
@@ -2869,7 +2875,9 @@ class ExamViews(View, LoginRequiredMixin):
answer_score = s.get_answer_score()
if answer_score == "unmarked":
index = exam.get_question_index(q)
# Use precomputed map to avoid repeated scanning/indexing of questions
index = question_index_map.get(q)
if index is not None:
unmarked.add(index)
# user_answers[cid].append(ans)
user_answers_marks[cid].append(answer_score)