From 92f9cabcc0394587b81633d696b1eec987dc354f Mon Sep 17 00:00:00 2001
From: Ross
Date: Mon, 16 Dec 2024 11:53:22 +0000
Subject: [PATCH] improve exam collections management
---
.../generic/examcollection_detail.html | 5 +++
.../generic/examcollection_form.html | 2 +-
generic/urls.py | 1 +
generic/views.py | 45 ++++++++++++-------
rad/views.py | 6 ++-
templates/exam_list.html | 7 ++-
templates/index.html | 12 +++++
7 files changed, 58 insertions(+), 20 deletions(-)
diff --git a/generic/templates/generic/examcollection_detail.html b/generic/templates/generic/examcollection_detail.html
index 3b44338e..7d59fb3c 100755
--- a/generic/templates/generic/examcollection_detail.html
+++ b/generic/templates/generic/examcollection_detail.html
@@ -19,6 +19,7 @@ This collection contains the following exams
{{ exam }} - (Edit)
{% endfor %}
+View exam list
Longs Exams:
@@ -26,6 +27,7 @@ This collection contains the following exams
- {{ exam }} - (Edit)
{% endfor %}
+View exam list
Rapids Exams:
@@ -33,6 +35,7 @@ This collection contains the following exams
- {{ exam }} - (Edit)
{% endfor %}
+View exam list
Physics Exams:
@@ -40,6 +43,7 @@ This collection contains the following exams
- {{ exam }} - (Edit)
{% endfor %}
+View exam list
SBAs Exams:
@@ -47,6 +51,7 @@ This collection contains the following exams
- {{ exam }} - (Edit)
{% endfor %}
+View exam list
diff --git a/generic/templates/generic/examcollection_form.html b/generic/templates/generic/examcollection_form.html
index 5ff99020..4be1373b 100755
--- a/generic/templates/generic/examcollection_form.html
+++ b/generic/templates/generic/examcollection_form.html
@@ -20,7 +20,7 @@
Edit Exam Collection {{object.name}}
{% endblock %}
\ No newline at end of file
diff --git a/generic/urls.py b/generic/urls.py
index 6446b630..c57f14f2 100755
--- a/generic/urls.py
+++ b/generic/urls.py
@@ -396,6 +396,7 @@ def generic_exam_urls(generic_exam_view: GenericExamViews):
name="exam_answers_submit",
),
path("exam/", generic_exam_view.exam_list, name="exam_list"),
+ path("exam//collection", generic_exam_view.exam_list_collection, name="exam_list_collection"),
path("exam/all", generic_exam_view.exam_list_all, name="exam_list_all"),
path(
"exam//order_questions",
diff --git a/generic/views.py b/generic/views.py
index 281e6c71..96ebdff7 100644
--- a/generic/views.py
+++ b/generic/views.py
@@ -759,24 +759,36 @@ class ExamViews(View, LoginRequiredMixin):
return HttpResponse("Done")
@method_decorator(login_required)
- def exam_list(self, request, all=False):
- if not self.check_user_access(request.user):
- # raise PermissionDenied
- exam_list = self.Exam.objects.filter(
- author__id=request.user.id, exam_mode=True
- ).order_by("name")
+ def exam_list_collection(self, request, collection_id):
+ collection = get_object_or_404(ExamCollection, pk=collection_id)
- exam_list = exam_list | self.Exam.objects.filter(
- markers__id=request.user.id, exam_mode=True
- ).order_by("name")
- else:
- exam_list = (
- self.Exam.objects.prefetch_related(
- "valid_user_users", "valid_cid_users"
+ if not request.user in collection.author.all():
+ raise PermissionDenied
+
+ return self.exam_list(request, all=True, collection=collection)
+
+ @method_decorator(login_required)
+ def exam_list(self, request, all=False, collection=None):
+ if collection is None:
+ if not self.check_user_access(request.user):
+ # raise PermissionDenied
+ exam_list = self.Exam.objects.filter(
+ author__id=request.user.id, exam_mode=True
+ ).order_by("name")
+
+ exam_list = exam_list | self.Exam.objects.filter(
+ markers__id=request.user.id, exam_mode=True
+ ).order_by("name")
+ else:
+ exam_list = (
+ self.Exam.objects.prefetch_related(
+ "valid_user_users", "valid_cid_users"
+ )
+ .filter(exam_mode=True)
+ .order_by("name")
)
- .filter(exam_mode=True)
- .order_by("name")
- )
+ else:
+ exam_list = self.Exam.objects.filter(exam_mode=True, examcollection__in=[collection]).order_by("name")
if not all:
exam_list = exam_list.filter(archive=False).order_by("name")
@@ -794,6 +806,7 @@ class ExamViews(View, LoginRequiredMixin):
"app_name": self.app_name,
"view_all": all,
"marking": marking,
+ "collection": collection,
},
)
diff --git a/rad/views.py b/rad/views.py
index bf6e0dde..36c8f233 100644
--- a/rad/views.py
+++ b/rad/views.py
@@ -65,7 +65,7 @@ from rapids.views import GenericExamViews as RapidsExamsViews
from longs.views import GenericExamViews as LongsExamViews
from generic.forms import QuestionNoteForm
-from generic.models import CidUser, QuestionNote, Supervisor, UserGrades, UserProfile
+from generic.models import CidUser, ExamCollection, QuestionNote, Supervisor, UserGrades, UserProfile
from django_filters.views import FilterView
@@ -99,9 +99,11 @@ def profile(request):
return render(request, "profile.html", {"user": user})
def index(request):
+
+ collections = ExamCollection.objects.filter(archive=False, author=request.user)
rcr_assessor = request.user.groups.filter(Q(name="rcr_radiology_assessor") | Q(name="rcr_oncology_assessor")| Q(name="rcr_assessor")).exists()
- return render(request, "index.html", {"rcr_assessor": rcr_assessor})
+ return render(request, "index.html", {"rcr_assessor": rcr_assessor, "collections": collections})
@user_is_cid_user_manager
def account_profile(request, slug):
diff --git a/templates/exam_list.html b/templates/exam_list.html
index 2d90f8cd..c8052aba 100644
--- a/templates/exam_list.html
+++ b/templates/exam_list.html
@@ -2,10 +2,15 @@
{% block content %}
Examinations
+
+ {% if collection %}
+ Collection: {{collection.name}}
+ {% endif %}
+
Help
- This page shows the currently active examations (that you have access to manage).
+ This page shows the currently active examinations (that you have access to manage).
Exams that are active will be available for candidates to take.
diff --git a/templates/index.html b/templates/index.html
index 24809246..24235be0 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -42,6 +42,18 @@
{% endif %}
+
+ {% if collections %}
+ Exam collections
+
+
+ {% endif %}
+
+
RTS is available here