From e6469e70f0793b3ce3c91821c2e0a030dc6c0b7f Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 24 Jul 2023 09:19:08 +0100 Subject: [PATCH] reoorganise atlas modules --- atlas/models.py | 39 +++- .../atlas/collection_case_view_take.html | 8 +- atlas/templates/atlas/collection_detail.html | 1 + ...view.html => collection_review_start.html} | 0 atlas/templates/atlas/collection_take.html | 53 ------ .../atlas/collection_take_overview.html | 27 ++- .../atlas/collection_take_start.html | 61 +++++++ atlas/urls.py | 11 +- atlas/views.py | 166 +++++++++++++----- generic/models.py | 23 ++- 10 files changed, 275 insertions(+), 114 deletions(-) rename atlas/templates/atlas/{collection_review.html => collection_review_start.html} (100%) delete mode 100644 atlas/templates/atlas/collection_take.html create mode 100644 atlas/templates/atlas/collection_take_start.html diff --git a/atlas/models.py b/atlas/models.py index 280856f3..9b08d44c 100644 --- a/atlas/models.py +++ b/atlas/models.py @@ -1,6 +1,8 @@ import json import os import pathlib + +from django.http import Http404 from rad.settings import REMOTE_URL from django.db.models.fields.files import ImageField from django.db.models.fields.related import ForeignKey @@ -506,11 +508,46 @@ class CaseCollection(ExamCollectionGenericBase): return reverse("atlas:collection_detail", kwargs={"pk": self.pk}) def get_take_url(self): - return reverse("atlas:collection_take", kwargs={"pk": self.pk}) + return reverse("atlas:collection_take_start", kwargs={"pk": self.pk}) def __str__(self) -> str: return self.name + def review_only(self) -> bool: + """Returns True if a users cannot submit responses + + Returns: + bool: _description_ + """ + if self.collection_type == self.COLLECTION_TYPE_CHOICES.REVIEW: + return True + + return False + + + def check_user_can_take(self, cid, passcode, request): + """ + Helper to check if a user is allowed to access a collection + + Args: + cid (_type_): _description_ + passcode (_type_): _description_ + request (_type_): _description_ + + Raises: + Http404: If user does not have access + """ + if not self.active: + raise Http404("Exam not found") + + #if self.collection_is_review(): + # return True + + #if not self.self_review: + + if not self.check_cid_user(cid, passcode, request): + raise Http404("Error accessing exam") + class CaseDetail(models.Model): case = models.ForeignKey(Case, on_delete=models.CASCADE) diff --git a/atlas/templates/atlas/collection_case_view_take.html b/atlas/templates/atlas/collection_case_view_take.html index 32e19b54..71b7e5e6 100644 --- a/atlas/templates/atlas/collection_case_view_take.html +++ b/atlas/templates/atlas/collection_case_view_take.html @@ -7,6 +7,12 @@ : {{case.title}} {% endif %} + + {% if collection.publish_results or cid_user_exam.completed %} + review + {% endif %} + + {% if show_description and case.description %} @@ -72,7 +78,7 @@
{% csrf_token %} {% if collection.collection_type == "REP" %}
-
+
{{form}}
diff --git a/atlas/templates/atlas/collection_detail.html b/atlas/templates/atlas/collection_detail.html index 0607528c..b73e42ba 100644 --- a/atlas/templates/atlas/collection_detail.html +++ b/atlas/templates/atlas/collection_detail.html @@ -6,6 +6,7 @@ Publish results: {{collection.publish_results}}
Active: {{collection.active}}
Collection Type: {{collection.collection_type}}
+ Self review: {{collection.self_review}}

Cases