test updating view
This commit is contained in:
+15
-7
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user