start user score pages
This commit is contained in:
@@ -580,6 +580,56 @@ def exam_scores_cid(request, pk):
|
||||
},
|
||||
)
|
||||
|
||||
def exam_scores_cid_user(request, pk, sk):
|
||||
exam = get_object_or_404(Exam, pk=pk)
|
||||
|
||||
# TODO:Need some kind of test for cid
|
||||
cid = sk
|
||||
|
||||
questions = exam.exam_questions.all()
|
||||
|
||||
answers_and_marks = []
|
||||
answers_marks = []
|
||||
answers = []
|
||||
|
||||
for q in questions:
|
||||
# Get user answer
|
||||
s = q.cid_user_answers.filter(cid=cid)
|
||||
if not s:
|
||||
# skip if no answer
|
||||
answers_marks.append(0)
|
||||
answers.append("")
|
||||
continue
|
||||
|
||||
ans = s[0].answer
|
||||
if q.answers.filter(answer__iexact=ans, status=Answer.MarkOptions.CORRECT).first() is not None:
|
||||
a = 2
|
||||
elif q.answers.filter(answer__iexact=ans, status=Answer.MarkOptions.HALF_MARK).first() is not None:
|
||||
a = 1
|
||||
else:
|
||||
a = 0
|
||||
answers.append(ans)
|
||||
answers_marks.append(a)
|
||||
answers_and_marks.append((ans, a))
|
||||
|
||||
score = sum(answers_marks)
|
||||
|
||||
total = len(questions)
|
||||
|
||||
return render(
|
||||
request,
|
||||
"anatomy/exam_scores_user.html",
|
||||
{
|
||||
"exam": exam,
|
||||
"cid": cid,
|
||||
"questions": questions,
|
||||
"answers": answers,
|
||||
"answers_marks": answers_marks,
|
||||
"score": score,
|
||||
"answers_and_marks": answers_and_marks,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
def exam_scores(request, pk):
|
||||
|
||||
Reference in New Issue
Block a user