diff --git a/atlas/templates/atlas/collection_take_overview.html b/atlas/templates/atlas/collection_take_overview.html new file mode 100644 index 00000000..a9ac914c --- /dev/null +++ b/atlas/templates/atlas/collection_take_overview.html @@ -0,0 +1,25 @@ +{% extends 'base.html' %} + +{% block content %} + CID: {{cid}} + +

Collection: {{collection.name}}

+ +

Questions

+ {{answer_count}} out of {{collection_length}} questions answered. Click to go to question. +
+ {% for question, answer in question_answer_tuples %} + + {% endfor %} +
+ + Start time: {{cid_user_collection.start_time}} + +{% endblock %} + +{% block js %} + +{% endblock %} diff --git a/atlas/urls.py b/atlas/urls.py index 14e211da..81a6207b 100755 --- a/atlas/urls.py +++ b/atlas/urls.py @@ -18,7 +18,7 @@ urlpatterns = [ path("collection//delete", views.CaseCollectionDelete.as_view(), name="collection_delete"), path("collection//update", views.CaseCollectionUpdate.as_view(), name="collection_update"), path("collection/", views.collection_detail_view, name="collection_detail_view"), - #path("collection//take//", views.collection_detail_view_take, name="collection_detail_view_take"), + path("collection//take//", views.collection_take_overview, name="collection_take_overview"), path("collection//", views.collection_case_view, name="collection_case_view"), path("collection///take//", views.collection_case_view_take, name="collection_case_view_take"), path("condition/", views.ConditionView.as_view(), name="condition_view"), diff --git a/atlas/views.py b/atlas/views.py index 2471d093..bd030922 100755 --- a/atlas/views.py +++ b/atlas/views.py @@ -47,6 +47,7 @@ from .models import ( Case, CaseCollection, CaseDetail, + CidReportAnswer, Condition, PathologicalProcess, Presentation, @@ -1055,12 +1056,49 @@ def collection_detail_view(request, pk): request, "atlas/collection_detail_view.html", {"collection": collection} ) -#def collection_detail_view_take(request, pk, cid, passcode): -# collection = get_object_or_404(CaseCollection, pk=pk) -# -# return render( -# request, "atlas/collection_detail_view.html", {"collection": collection} -# ) +def collection_take_overview(request, pk, cid, passcode): + collection = get_object_or_404(CaseCollection, pk=pk) + + if not collection.active: + raise Http404("Exam not found") + + if not collection.check_cid_user(cid, passcode): + raise Http404("Error accessing exam") + + cases = collection.cases.all().order_by("casedetail__sort_order").prefetch_related() + + case_details = CaseDetail.objects.get(case__in=cases, collection=collection) + answers = CidReportAnswer.objects.filter(cid=cid, question__in=case_details) + + answer_question_map = {} + for ans in answers: + answer_question_map[ans.question] = ans + + question_answer_tuples = [] + answer_count = 0 + for q in cases: + if q in answer_question_map and answer_question_map[q].answer: + question_answer_tuples.append((q, answer_question_map[q])) + answer_count += 1 + else: + question_answer_tuples.append((q, None)) + + c = CidUser.objects.filter(cid=cid).first() + cid_user_exam = collection.get_or_create_cid_user_exam(cid_user=c) + + return render( + request, + "sbas/exam_take_overview.html", + { + "collection": collection, + "cid": cid, + "question_answer_tuples": question_answer_tuples, + "answer_count": answer_count, + "collection_length": len(cases), + "passcode": passcode, + "cid_user_exam": cid_user_exam, + }, + ) def collection_case_view_take(request, pk, case_number, cid, passcode): return collection_case_view(request, pk, case_number, True, cid, passcode)