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 %} + +{% 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 @@
{% if exam.exam_mode %} +

{% endif %} diff --git a/rapids/templates/rapids/exam_scores_user.html b/rapids/templates/rapids/exam_scores_user.html index 207922ac..5be9d332 100644 --- a/rapids/templates/rapids/exam_scores_user.html +++ b/rapids/templates/rapids/exam_scores_user.html @@ -20,16 +20,16 @@ @@ -90,3 +90,14 @@ }); {% endblock %} + + +{% block css %} + +{% endblock css %} + \ No newline at end of file diff --git a/rapids/tests/test_urls.py b/rapids/tests/test_urls.py index 3423533e..8b982c98 100644 --- a/rapids/tests/test_urls.py +++ b/rapids/tests/test_urls.py @@ -306,7 +306,7 @@ def test_supervisor_management(db, faker, client, create_cid_manager, django_use assert response.status_code == 200 soup = BeautifulSoup(response.content, "html.parser") - assert len(soup.find(id="supervisor-list").find_all("li")) == 2 + assert len(soup.find(id="tbody").find_all("tr")) == 2 response = client.get(reverse(f"generic:supervisor_detail", kwargs={"pk": s1.pk})) soup = BeautifulSoup(response.content, "html.parser") diff --git a/templates/user_score_header.html b/templates/user_score_header.html index 937f1a7e..9e9604c5 100644 --- a/templates/user_score_header.html +++ b/templates/user_score_header.html @@ -22,7 +22,7 @@
{% else %} {% if not exam.publish_results %} - + {% endif %} {% endif %}