From 0ba0785f537eb11f315c4f1eb696564723595a66 Mon Sep 17 00:00:00 2001 From: Ross Date: Fri, 17 Dec 2021 16:40:42 +0000 Subject: [PATCH] . --- rad/views.py | 82 +++++++++++++++++++++++---------------- templates/cid_scores.html | 36 ++++++++++------- 2 files changed, 72 insertions(+), 46 deletions(-) diff --git a/rad/views.py b/rad/views.py index 8e1df77c..a9ecf05e 100644 --- a/rad/views.py +++ b/rad/views.py @@ -88,41 +88,56 @@ def cid_scores(request, pk, passcode): print(cid_user.passcode) # questions = exam.exam_questions.all() - physics_answers = PhysicsCidUserAnswer.objects.filter(cid=cid) - anatomy_answers = AnatomyCidUserAnswer.objects.filter(cid=cid) - rapids_answers = RapidsCidUserAnswer.objects.filter(cid=cid) - longs_answers = LongsCidUserAnswer.objects.filter(cid=cid) - sbas_answers = SbasCidUserAnswer.objects.filter(cid=cid) - - # if ( - # not physics_answers - # and not anatomy_answers - # and not rapids_answers - # and not longs_answers - # and not sbas_answers - # ): - # raise Http404("cid not found") - - #kwargs = {"publish_results": True} + EXAM_ANSWER_MAP = { + "physics" : (PhysicsCidUserAnswer, PhysicsExam), + "anatomy" : (AnatomyCidUserAnswer, AnatomyExam), + "rapids" : (RapidsCidUserAnswer, RapidsExam), + "longs" : (LongsCidUserAnswer, LongsExam), + "sbas" : (SbasCidUserAnswer, SbasExam), + } kwargs = {"exam_mode": True} - #if request.user.groups.filter(name="view_all_results").exists(): - # kwargs = {} + exams = [] + for exam_type in EXAM_ANSWER_MAP: + exam_answers = EXAM_ANSWER_MAP[exam_type].objects.filter(cid=cid) + exam_ids = exam_answers.values_list("exam").distinct() + exams.append((exam_type, PhysicsExam.objects.filter(id__in=exam_ids, **kwargs))) - physics_exam_ids = physics_answers.values_list("exam").distinct() - physics_exams = PhysicsExam.objects.filter(id__in=physics_exam_ids, **kwargs) - anatomy_exam_ids = anatomy_answers.values_list("exam").distinct() - anatomy_exams = AnatomyExam.objects.filter(id__in=anatomy_exam_ids, **kwargs) + #physics_answers = PhysicsCidUserAnswer.objects.filter(cid=cid) + #anatomy_answers = AnatomyCidUserAnswer.objects.filter(cid=cid) + #rapids_answers = RapidsCidUserAnswer.objects.filter(cid=cid) + #longs_answers = LongsCidUserAnswer.objects.filter(cid=cid) + #sbas_answers = SbasCidUserAnswer.objects.filter(cid=cid) - rapids_exam_ids = rapids_answers.values_list("exam").distinct() - rapid_exams = RapidsExam.objects.filter(id__in=rapids_exam_ids, **kwargs) + ## if ( + ## not physics_answers + ## and not anatomy_answers + ## and not rapids_answers + ## and not longs_answers + ## and not sbas_answers + ## ): + ## raise Http404("cid not found") - longs_exam_ids = longs_answers.values_list("exam").distinct() - longs_exams = LongsExam.objects.filter(id__in=longs_exam_ids, **kwargs) + ##kwargs = {"publish_results": True} - sbas_exam_ids = sbas_answers.values_list("exam").distinct() - sba_exams = SbasExam.objects.filter(id__in=sbas_exam_ids, **kwargs) + ##if request.user.groups.filter(name="view_all_results").exists(): + ## kwargs = {} + + #physics_exam_ids = physics_answers.values_list("exam").distinct() + #physics_exams = PhysicsExam.objects.filter(id__in=physics_exam_ids, **kwargs) + + #anatomy_exam_ids = anatomy_answers.values_list("exam").distinct() + #anatomy_exams = AnatomyExam.objects.filter(id__in=anatomy_exam_ids, **kwargs) + + #rapids_exam_ids = rapids_answers.values_list("exam").distinct() + #rapid_exams = RapidsExam.objects.filter(id__in=rapids_exam_ids, **kwargs) + + #longs_exam_ids = longs_answers.values_list("exam").distinct() + #longs_exams = LongsExam.objects.filter(id__in=longs_exam_ids, **kwargs) + + #sbas_exam_ids = sbas_answers.values_list("exam").distinct() + #sba_exams = SbasExam.objects.filter(id__in=sbas_exam_ids, **kwargs) available_exams = cid_user.get_cid_exams() @@ -130,11 +145,12 @@ def cid_scores(request, pk, passcode): request, "cid_scores.html", { - "physics_exams": physics_exams, - "anatomy_exams": anatomy_exams, - "rapid_exams": rapid_exams, - "longs_exams": longs_exams, - "sba_exams": sba_exams, + #"physics_exams": physics_exams, + #"anatomy_exams": anatomy_exams, + #"rapid_exams": rapid_exams, + #"longs_exams": longs_exams, + #"sba_exams": sba_exams, + "all_exams": exams, "cid": cid, "passcode": passcode, "cid_user": cid_user, diff --git a/templates/cid_scores.html b/templates/cid_scores.html index ee99fc12..366dcd29 100644 --- a/templates/cid_scores.html +++ b/templates/cid_scores.html @@ -5,18 +5,28 @@

CID: {{ cid }}

Assigned exams

The following exams will be available to take when active. - {% for t, exams in available_exams %} -

{{t}}

- - {% endfor %} + {% for t, exams in available_exams %} +

{{t}}

+ + {% endfor %} -

Exam results

- The following exam results been found. Click to view answers (and scores when the results are published): - {% if physics_exams %} +

Exam results

+ The following exam results been found. Click to view answers (and scores when the results are published): + {% for exam_type, exams in all_exams %} + {% if exams %} +

{{exam_type}}

+ + {% endif %} + {% endfor %} + {% comment %} {% if physics_exams %}

Physics

- {% endif %} - + {% endif %} {% endcomment %} + {% endblock %}