From 562fa4ab8c6d19151b012ec8e5a294db7eca8c41 Mon Sep 17 00:00:00 2001 From: Ross Date: Sat, 18 Dec 2021 18:48:38 +0000 Subject: [PATCH] . --- rapids/templates/rapids/exam_scores.html | 4 +-- rapids/views.py | 43 +++++++++++++----------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/rapids/templates/rapids/exam_scores.html b/rapids/templates/rapids/exam_scores.html index 7c9c70fc..f72701ce 100644 --- a/rapids/templates/rapids/exam_scores.html +++ b/rapids/templates/rapids/exam_scores.html @@ -62,8 +62,8 @@ [A] {% endif %} - {% for ans, score in by_question|get_item:question %} - {{ans}} + {% for cid in cids %} + {{ans_by_question|get_item:question}} {% endfor %} {% endfor %} diff --git a/rapids/views.py b/rapids/views.py index b7c7ee42..ac070213 100755 --- a/rapids/views.py +++ b/rapids/views.py @@ -526,7 +526,9 @@ def loadJsonAnswer(answer): exam = get_object_or_404(Exam, pk=eid) if not exam.check_cid_user(answer["cid"], answer["passcode"]): - return False, JsonResponse({"success": False, "error": "invalid cid / passcode"}) + return False, JsonResponse( + {"success": False, "error": "invalid cid / passcode"} + ) # if not exam.active: # return False, JsonResponse( @@ -580,6 +582,7 @@ def mark_all(request, exam_pk, sk): def mark_review(request, exam_pk, sk): return mark(request, exam_pk, sk, unmarked_exam_answers_only=False, review=True) + @login_required def exam_scores_cid2(request, pk): exam = get_object_or_404(Exam, pk=pk) @@ -592,18 +595,16 @@ def exam_scores_cid2(request, pk): user_answers = defaultdict(list) user_names = {} - by_question = defaultdict(list) + score_by_question = defaultdict(dict) + ans_by_question = defaultdict(dict) unmarked = set() questions = exam.exam_questions.all() - cid_user_answers = ( - CidUserAnswer.objects.filter(question__in=questions, exam__id=pk) - ) + cid_user_answers = CidUserAnswer.objects.filter(question__in=questions, exam__id=pk) cids = set() - # Loop through all candidates for cid_user_answer in cid_user_answers: # Convoluted (probably...) @@ -614,14 +615,13 @@ def exam_scores_cid2(request, pk): q = cid_user_answer.question - - if not s: - # skip if no answer - user_answers_marks[cid].append(0) - user_answers[cid].append("") - by_question[q].append(("", 0)) - continue - elif s.normal: + # if not s: + # # skip if no answer + # user_answers_marks[cid].append(0) + # user_answers[cid].append("") + # by_question[q].append(("", 0)) + # continue + if s.normal: ans = "Normal" else: ans = s.answer @@ -633,7 +633,8 @@ def exam_scores_cid2(request, pk): user_answers_marks[cid].append(answer_score) user_answers_and_marks[cid].append((ans, answer_score)) - by_question[q].append((ans, answer_score)) + score_by_question[q][cid] = answer_score + ans_by_question[q][cid] = ans user_scores = {} user_scores_normalised = {} @@ -677,11 +678,12 @@ def exam_scores_cid2(request, pk): request, "rapids/exam_scores.html", { - "cids": cids, + "cids": sorted(cids), "exam": exam, "unmarked": unmarked, "questions": questions, - "by_question": by_question, + "score_by_question": score_by_question, + "ans_by_question": ans_by_question, "user_answers": dict(user_answers), "user_answers_marks": dict(user_answers_marks), "user_scores": user_scores, @@ -697,6 +699,7 @@ def exam_scores_cid2(request, pk): }, ) + # @user_passes_test(user_is_admin, login_url="/accounts/login") @login_required def mark(request, exam_pk, sk, unmarked_exam_answers_only=True, review=False): @@ -1027,7 +1030,7 @@ def exam_scores_cid_user(request, pk, cid, passcode): { "exam": exam, "cid": cid, - "passcode" : passcode, + "passcode": passcode, "questions": questions, "answers": answers, "answers_marks": answers_marks, @@ -1044,7 +1047,9 @@ class QuestionDelete(AuthorOrCheckerRequiredMixin, DeleteView): success_url = reverse_lazy("rapids:rapid_view") -RapidExamViews = ExamViews(Exam, Rapid, CidUserAnswer, "rapids", "rapid", loadJsonAnswer) +RapidExamViews = ExamViews( + Exam, Rapid, CidUserAnswer, "rapids", "rapid", loadJsonAnswer +) class ExamCreate(RevisionMixin, LoginRequiredMixin, CreateView):