This commit is contained in:
Ross
2021-12-19 14:57:47 +00:00
parent fccf25e2a1
commit afb1dacbb8
3 changed files with 60 additions and 16 deletions
+39 -10
View File
@@ -446,15 +446,16 @@ class ExamViews(View, LoginRequiredMixin):
"region",
"examination",
"question_type",
).all()
# .prefetch_related(
# Prefetch(
# "answers",
# queryset=self.Answer.objects.filter(
# proposed=False, status=self.Answer.MarkOptions.CORRECT
# ),
# )
# )
)
.all()
.prefetch_related(
Prefetch(
"answers",
queryset=self.Answer.objects.filter(proposed=False, status=self.Answer.MarkOptions.CORRECT),
to_attr="prefetched_primary_answer"
#queryset=self.Answer.objects.filter(),
),
)
)
elif self.app_name == "rapids":
questions = (
@@ -622,7 +623,35 @@ class ExamViews(View, LoginRequiredMixin):
if not self.check_user_access(request.user, pk):
raise PermissionDenied
questions = exam.exam_questions.all()
if self.app_name == "anatomy":
questions = (
exam.exam_questions.select_related(
"modality",
"structure",
"body_part",
"region",
"examination",
"question_type",
)
.all()
.prefetch_related(
#"cid_user_answers",
Prefetch(
"answers",
queryset=self.Answer.objects.filter(proposed=False, status=self.Answer.MarkOptions.CORRECT),
to_attr="prefetched_primary_answer"
#queryset=self.Answer.objects.filter(),
),
Prefetch(
"cid_user_answers",
queryset=self.CidUserAnswer.objects.filter(score=self.Answer.MarkOptions.UNMARKED, exam__id=pk),
to_attr="prefetched_unmarked_cid_answers"
#queryset=self.Answer.objects.filter(),
),
)
)
else:
questions = exam.exam_questions.all()
# Handle exams that require double marking
try: