diff --git a/anatomy/tests/test_anatomy_exams.py b/anatomy/tests/test_anatomy_exams.py
index 44ecf67a..c3ee1d56 100644
--- a/anatomy/tests/test_anatomy_exams.py
+++ b/anatomy/tests/test_anatomy_exams.py
@@ -34,7 +34,7 @@ APP_NAME = "anatomy"
def create_exam(db):
exam: Exam = AnatomyExamViews.Exam.objects.create(
- name="Cid Exam", exam_mode=True, active=True
+ name="Cid Exam", exam_mode=True, active=True, open_access=False, exam_open_access=False
)
group1: CidUserGroup = CidUserGroup.objects.get(name="Group1")
@@ -194,6 +194,8 @@ def test_exams(db, client):
exam.save()
res = client.get(exam_metadata["url"])
+ print("PRE ERRER", exam_metadata["url"])
+ print(res.content)
assert res.status_code == 404
exam.active = True
@@ -365,7 +367,7 @@ def test_exams(db, client):
cid_exam_scores_soup = BeautifulSoup(cid_exam_scores_res.content, "html.parser")
# Check that we have an alert that exams are not published
- alert = cid_exam_scores_soup.find("div", {"class": "alert"})
+ alert = cid_exam_scores_soup.find("div", {"class": "no-results"})
assert "Results are not currently published." in str(alert)
answer_lis = cid_exam_scores_soup.find(
diff --git a/generic/models.py b/generic/models.py
index bf2f0894..0a040113 100644
--- a/generic/models.py
+++ b/generic/models.py
@@ -702,7 +702,7 @@ class ExamOrCollectionGenericBase(models.Model, AuthorMixin):
allow_authors: bool = True,
):
"""Checks if a user (cid or otherwise) is allowed to access (and take) the exam"""
- print(f"Check cid user: {cid=}, {passcode=}, exam_id={self.pk}")
+ print(f"Check cid user: {cid=}, {passcode=}, exam_id={self.pk}, {user=}, {user_id=}, {allow_authors=}")
if user is not None and user.is_superuser:
return True
@@ -724,6 +724,7 @@ class ExamOrCollectionGenericBase(models.Model, AuthorMixin):
return False
+
# Start by checking if the logged in user can access
if user_id is not None:
if self.valid_user_users.filter(pk=user_id).exists():
diff --git a/generic/templates/generic/exam_overview_headers.html b/generic/templates/generic/exam_overview_headers.html
index 2b8fc48f..2f7446f6 100644
--- a/generic/templates/generic/exam_overview_headers.html
+++ b/generic/templates/generic/exam_overview_headers.html
@@ -28,6 +28,11 @@
{% endif %}
{% endif %}
+{% if exam.archive %}
+
+ This exam is archived. Results and submitted answers will not be available to candidates. They can still be viewed by supervisors.
+
+{% endif %}
This exam has {{question_number}} questions.
Time limit: {{exam.time_limit}} seconds [{{exam.get_time_limit}}]
@@ -101,7 +106,7 @@ Open access: {{ exam.open_access }}
id="exam-publish-results-switch" data-posturl="{% url exam.get_app_name|add:':exam_toggle_results_published' pk=exam.pk %}"
{% if exam.publish_results %}checked{% endif %}> [When checked the exam results will be available to users on this site]
- {% if exam.get_app_name == "anatomy" or exam.get_app_name == "rapids" or exam.get_app_name == "longs" %}
+ {% if exam.get_app_name == "anatomy" or exam.get_app_name == "longs" %}
{% endif %}
{% endif %}
diff --git a/generic/views.py b/generic/views.py
index 401e1c3f..65d4b9f6 100644
--- a/generic/views.py
+++ b/generic/views.py
@@ -184,6 +184,7 @@ def get_user_exams(user, supervisor_view=False):
if supervisor_view:
kwargs["results_supervisor_visible"] = True
+ del kwargs["archive"]
exams = []
for exam_type in EXAM_ANSWER_MAP:
@@ -527,7 +528,7 @@ class ExamViews(View, LoginRequiredMixin):
if (exam.open_access and exam.active) or user in exam.get_author_objects():
return True
- if exam.cid_user_exam.filter(user_user=user):
+ if user.is_authenticated and exam.active and exam.cid_user_exam.filter(user_user=user):
return True
if marker and user in exam.markers.all():
@@ -1914,10 +1915,12 @@ class ExamViews(View, LoginRequiredMixin):
user_id = None
else:
user_id = request.user.pk
+ print(0)
if exam.exam_mode and not exam.check_cid_user(
cid, passcode, request.user, user_id
):
raise Http404("No available exam")
+ print(1)
# exam_json_cache = cache.get("{}_exam_json_{}".format(self.app_name, pk))
@@ -2116,10 +2119,10 @@ class ExamViews(View, LoginRequiredMixin):
# check for supervisor access
raise Http404("Error accessing exam")
- view_all_results = True
else:
if user is None:
raise Exception("user must be defined")
+ view_all_results = True
if user is not None:
request.user = user
@@ -3853,6 +3856,8 @@ def supervisor_trainee(request, pk, trainee_id):
exams = get_user_exams(trainee, supervisor_view=True)
+ print(exams)
+
print(trainee)
return render(
diff --git a/rapids/templates/rapids/exam_overview.html b/rapids/templates/rapids/exam_overview.html
index f200eab1..495263ea 100644
--- a/rapids/templates/rapids/exam_overview.html
+++ b/rapids/templates/rapids/exam_overview.html
@@ -10,6 +10,7 @@