allow rodering questions

This commit is contained in:
Ross
2024-08-28 18:59:35 +01:00
parent 0054d832cd
commit 98d45fbdfc
3 changed files with 28 additions and 8 deletions
@@ -107,6 +107,14 @@ Author(s): {% for author in exam.author.all %}
{{ author }}{% if not forloop.last %}, {% endif %}
{% endfor %}<br/>
<details>
<summary>Extra</summary>
<button title="This will clear all user answers and attempts"
hx-post="{% url exam.get_app_name|add:':order_questions' exam.pk %}"
hx-swap="outerHTML"
>Order questions</button>
</details>
{% block css %}
<style>
.answer-management[open] {
+9 -8
View File
@@ -239,11 +239,11 @@ def generic_exam_urls(generic_exam_view: GenericExamViews):
generic_exam_view.exam_question_detail,
name="exam_question_detail",
),
#path(
# path(
# "exam/<int:pk>/question/<int:sk>/answer/<str:user_or_cid>",
# generic_exam_view.exam_question_user_answer,
# name="exam_question_user_answer",
#),
# ),
path(
"exam/<int:pk>/question/<int:sk>/answer/<str:c_or_u>/<str:user_or_cid>",
generic_exam_view.exam_question_user_answer,
@@ -342,13 +342,14 @@ def generic_exam_urls(generic_exam_view: GenericExamViews):
),
path("exam/", generic_exam_view.exam_list, name="exam_list"),
path("exam/all", generic_exam_view.exam_list_all, name="exam_list_all"),
path("exam/<int:exam_id>/order_questions", generic_exam_view.order_questions, name="order_questions"),
path("exam/<int:exam_id>/cids", generic_exam_view.exam_cids, name="exam_cids"),
#path("exam/<int:exam_id>/groups", generic_exam_view.exam_groups_edit, name="exam_groups_edit"),
path(
"exam/<int:exam_id>/reset_answers",
generic_exam_view.exam_reset_answers,
name="exam_reset_answers",
),
# path("exam/<int:exam_id>/groups", generic_exam_view.exam_groups_edit, name="exam_groups_edit"),
path(
"exam/<int:exam_id>/reset_answers",
generic_exam_view.exam_reset_answers,
name="exam_reset_answers",
),
path(
"exam/<int:exam_id>/cids/edit",
generic_exam_view.exam_cids_edit,
+11
View File
@@ -654,6 +654,16 @@ class ExamViews(View, LoginRequiredMixin):
def exam_list_all(self, request):
return self.exam_list(request, all=True)
def order_questions(self, request, exam_id):
if not self.check_user_edit_access(request.user):
raise PermissionDenied
exam = get_object_or_404(self.Exam, pk=exam_id)
exam.order_questions()
return HttpResponse("Done")
@method_decorator(login_required)
def exam_list(self, request, all=False):
if not self.check_user_access(request.user):
@@ -2566,6 +2576,7 @@ class ExamCloneMixin():
object.exam_questions.set(self.exam_questions)
object.author.set(self.author)
object.save()
object.order_questions()
return HttpResponseRedirect(object.get_absolute_url())