test updating view
This commit is contained in:
+16
-8
@@ -2816,16 +2816,22 @@ class ExamViews(View, LoginRequiredMixin):
|
|||||||
|
|
||||||
if self.app_name in ("physics", "sbas", "longs", "shorts"):
|
if self.app_name in ("physics", "sbas", "longs", "shorts"):
|
||||||
cached_scores = False
|
cached_scores = False
|
||||||
questions = exam.get_questions()
|
questions_qs = exam.get_questions()
|
||||||
else:
|
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)
|
# Materialize questions into a list so we can index and build a question->index map
|
||||||
cid_user_answers = self.UserAnswer.objects.select_related("question").filter(
|
questions = list(questions_qs)
|
||||||
question__in=questions, exam__id=pk
|
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()
|
cids = set()
|
||||||
|
|
||||||
@@ -2869,8 +2875,10 @@ class ExamViews(View, LoginRequiredMixin):
|
|||||||
|
|
||||||
answer_score = s.get_answer_score()
|
answer_score = s.get_answer_score()
|
||||||
if answer_score == "unmarked":
|
if answer_score == "unmarked":
|
||||||
index = exam.get_question_index(q)
|
# Use precomputed map to avoid repeated scanning/indexing of questions
|
||||||
unmarked.add(index)
|
index = question_index_map.get(q)
|
||||||
|
if index is not None:
|
||||||
|
unmarked.add(index)
|
||||||
# user_answers[cid].append(ans)
|
# user_answers[cid].append(ans)
|
||||||
user_answers_marks[cid].append(answer_score)
|
user_answers_marks[cid].append(answer_score)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user