improve exam collections management
This commit is contained in:
@@ -19,6 +19,7 @@ This collection contains the following exams
|
||||
<li><a href="{% url 'anatomy:exam_overview' exam.pk %}">{{ exam }}</a> - <a href="{% url 'anatomy:exam_update' exam.pk %}">(Edit)</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<a href="{% url 'anatomy:exam_list_collection' object.pk %}">View exam list</a>
|
||||
|
||||
<h2>Longs Exams:</h2>
|
||||
<ul>
|
||||
@@ -26,6 +27,7 @@ This collection contains the following exams
|
||||
<li><a href="{% url 'longs:exam_overview' exam.pk %}">{{ exam }}</a> - <a href="{% url 'longs:exam_update' exam.pk %}">(Edit)</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<a href="{% url 'longs:exam_list_collection' object.pk %}">View exam list</a>
|
||||
|
||||
<h2>Rapids Exams:</h2>
|
||||
<ul>
|
||||
@@ -33,6 +35,7 @@ This collection contains the following exams
|
||||
<li><a href="{% url 'rapids:exam_overview' exam.pk %}">{{ exam }}</a> - <a href="{% url 'rapids:exam_update' exam.pk %}">(Edit)</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<a href="{% url 'rapids:exam_list_collection' object.pk %}">View exam list</a>
|
||||
|
||||
<h2>Physics Exams:</h2>
|
||||
<ul>
|
||||
@@ -40,6 +43,7 @@ This collection contains the following exams
|
||||
<li><a href="{% url 'physics:exam_overview' exam.pk %}">{{ exam }}</a> - <a href="{% url 'physics:exam_update' exam.pk %}">(Edit)</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<a href="{% url 'physics:exam_list_collection' object.pk %}">View exam list</a>
|
||||
|
||||
<h2>SBAs Exams:</h2>
|
||||
<ul>
|
||||
@@ -47,6 +51,7 @@ This collection contains the following exams
|
||||
<li><a href="{% url 'sbas:exam_overview' exam.pk %}">{{ exam }}</a> - <a href="{% url 'sbas:exam_update' exam.pk %}">(Edit)</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<a href="{% url 'sbas:exam_list_collection' object.pk %}">View exam list</a>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
<h2>Edit Exam Collection {{object.name}}</h2>
|
||||
<form action="" method="post" enctype="multipart/form-data" id="examcollection-form">
|
||||
{% csrf_token %}
|
||||
{{ form|crispy }}
|
||||
{{ form|crispy }}
|
||||
<input type="submit" class="submit-button" value="Submit" name="submit">
|
||||
</form>
|
||||
{% endblock %}
|
||||
@@ -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/<int:collection_id>/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/<int:exam_id>/order_questions",
|
||||
|
||||
+29
-16
@@ -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,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user