From 7f4dbfec51cb7eaa32f18b051950a35d9d49fe32 Mon Sep 17 00:00:00 2001 From: Ross Date: Tue, 23 Feb 2021 21:12:50 +0000 Subject: [PATCH] . --- anatomy/tables.py | 2 + anatomy/templates/anatomy/exam_overview.html | 36 ++++++++++++++- anatomy/views.py | 2 +- generic/views.py | 48 +++++++++++++++----- longs/tables.py | 3 ++ longs/templates/longs/exam_overview.html | 36 ++++++++++++++- longs/views.py | 2 +- physics/views.py | 2 +- rapids/tables.py | 2 + rapids/templates/rapids/exam_overview.html | 38 +++++++++++++++- rapids/templates/rapids/mark.html | 4 +- rapids/views.py | 2 +- 12 files changed, 153 insertions(+), 24 deletions(-) diff --git a/anatomy/tables.py b/anatomy/tables.py index b4625fb9..d0a66c68 100644 --- a/anatomy/tables.py +++ b/anatomy/tables.py @@ -57,6 +57,8 @@ class AnatomyQuestionTable(tables.Table): ) exams = tables.ManyToManyColumn(verbose_name="Exams") + selection = tables.CheckBoxColumn(accessor="pk", orderable=False) + class Meta: model = AnatomyQuestion template_name = "django_tables2/bootstrap4.html" diff --git a/anatomy/templates/anatomy/exam_overview.html b/anatomy/templates/anatomy/exam_overview.html index e03b8aa4..9dc31beb 100644 --- a/anatomy/templates/anatomy/exam_overview.html +++ b/anatomy/templates/anatomy/exam_overview.html @@ -16,10 +16,10 @@

-
    +
      {% for question in questions.all %} -
    1. +
    2. thumbail {{ question.description }}
      @@ -33,6 +33,7 @@ Refresh JSON cache + {% endblock %} \ No newline at end of file diff --git a/anatomy/views.py b/anatomy/views.py index b3d3caec..cee79866 100644 --- a/anatomy/views.py +++ b/anatomy/views.py @@ -953,7 +953,7 @@ def question_save_annotation(request, pk): return JsonResponse(data, status=400) -AnatomyExamViews = ExamViews(Exam, "anatomy", "anatomy", loadJsonAnswer) +AnatomyExamViews = ExamViews(Exam, AnatomyQuestion, "anatomy", "anatomy", loadJsonAnswer) class UserAnswerDelete(SuperuserRequiredMixin, DeleteView): model = CidUserAnswer diff --git a/generic/views.py b/generic/views.py index ed517883..da4bb8c8 100644 --- a/generic/views.py +++ b/generic/views.py @@ -24,6 +24,9 @@ from .forms import ( from .models import Examination +from django.db.models import Case, When + + # Create your views here. @login_required def create_examination(request): @@ -52,8 +55,9 @@ def get_examination_id(request): class ExamViews(View, LoginRequiredMixin): - def __init__(self, exam, app, question_type, loadJsonAnswer): + def __init__(self, exam, question, app, question_type, loadJsonAnswer): self.Exam = exam + self.Question = question self.app_name = app self.question_type = question_type self.loadJsonAnswer = loadJsonAnswer @@ -127,19 +131,39 @@ class ExamViews(View, LoginRequiredMixin): exam = get_object_or_404(self.Exam, pk=pk) - if request.POST.get("set_open_access") == "true": - state = True - else: - state = False + if "set_open_access" in request.POST: + if request.POST.get("set_open_access") == "true": + state = True + else: + state = False - questions_changed = [] - for q in exam.exam_questions.all(): - q.open_access = state - q.save() - questions_changed.append(q.pk) + questions_changed = [] + for q in exam.exam_questions.all(): + q.open_access = state + q.save() + questions_changed.append(q.pk) - data = {"status": "success", "questions": questions_changed, "state": state} - return JsonResponse(data, status=200) + data = {"status": "success", "questions": questions_changed, "state": state} + return JsonResponse(data, status=200) + + if "set_exam_order" in request.POST: + new_order = json.loads(request.POST.get("set_exam_order")) + + preserved = Case(*[When(pk=pk, then=pos) for pos, pk in enumerate(new_order)]) + objects = self.Question.objects.filter(pk__in=new_order).order_by(preserved) + + if len(objects) != exam.exam_questions.count(): + data = {"status": "error, count does not match"} + return JsonResponse(data, status=400) + + exam.exam_questions.set(objects) + exam.save() + data = {"status": "success"} + return JsonResponse(data, status=200) + + + data = {"status": "error, unknown request"} + return JsonResponse(data, status=400) else: data = {"status": "error"} return JsonResponse(data, status=400) diff --git a/longs/tables.py b/longs/tables.py index a256bdb3..0b6d68f3 100755 --- a/longs/tables.py +++ b/longs/tables.py @@ -65,6 +65,8 @@ class LongTable(tables.Table): #series = tables.ManyToManyColumn(verbose_name="Exams") exams = tables.ManyToManyColumn(verbose_name="Exams") + selection = tables.CheckBoxColumn(accessor="pk", orderable=False) + class Meta: model = Long template_name = "django_tables2/bootstrap4.html" @@ -99,6 +101,7 @@ class LongSeriesTable(tables.Table): delete = tables.LinkColumn( "longs:long_series_delete", text="Delete", args=[A("pk")], orderable=False ) + selection = tables.CheckBoxColumn(accessor="pk", orderable=False) class Meta: model = LongSeries diff --git a/longs/templates/longs/exam_overview.html b/longs/templates/longs/exam_overview.html index f4a819bc..461fcabc 100644 --- a/longs/templates/longs/exam_overview.html +++ b/longs/templates/longs/exam_overview.html @@ -17,10 +17,10 @@

      -
        +
          {% for question in questions.all %} -
        1. +
        2. History: {{ question.history}}
          {% for series in question.series.all %} @@ -44,6 +44,7 @@ Refresh JSON cache + {% endblock %} \ No newline at end of file diff --git a/longs/views.py b/longs/views.py index f40a35ef..9c583115 100755 --- a/longs/views.py +++ b/longs/views.py @@ -931,4 +931,4 @@ def exam_scores_cid_user(request, pk, sk): ) -LongExamViews = ExamViews(Exam, "longs", "long", loadJsonAnswer) \ No newline at end of file +LongExamViews = ExamViews(Exam, Long, "longs", "long", loadJsonAnswer) \ No newline at end of file diff --git a/physics/views.py b/physics/views.py index 049dbcef..af919158 100644 --- a/physics/views.py +++ b/physics/views.py @@ -285,4 +285,4 @@ def loadJsonAnswer(answer): return True -PhysicsExamViews = ExamViews(Exam, "physics", "physics", loadJsonAnswer) \ No newline at end of file +PhysicsExamViews = ExamViews(Exam, Question, "physics", "physics", loadJsonAnswer) \ No newline at end of file diff --git a/rapids/tables.py b/rapids/tables.py index f6fa13ed..59efa961 100755 --- a/rapids/tables.py +++ b/rapids/tables.py @@ -44,6 +44,8 @@ class RapidTable(tables.Table): orderable=False) images = ImageColumn("images", orderable=False) + selection = tables.CheckBoxColumn(accessor="pk", orderable=False) + class Meta: model = Rapid template_name = "django_tables2/bootstrap4.html" diff --git a/rapids/templates/rapids/exam_overview.html b/rapids/templates/rapids/exam_overview.html index 5c3fa9ce..b915f176 100644 --- a/rapids/templates/rapids/exam_overview.html +++ b/rapids/templates/rapids/exam_overview.html @@ -16,10 +16,10 @@

          -
            +
              {% for question in questions.all %} -
            1. +
            2. {% for image in question.GetImages %} thumbail {% endfor %} @@ -39,6 +39,7 @@ Refresh JSON cache + {% endblock %} \ No newline at end of file diff --git a/rapids/templates/rapids/mark.html b/rapids/templates/rapids/mark.html index 9fdd605c..0cf37d5f 100644 --- a/rapids/templates/rapids/mark.html +++ b/rapids/templates/rapids/mark.html @@ -7,10 +7,10 @@ Edit {% if question.normal %}

              This question is normal

              -Answers will be automatically marked.
              +Answers will be automatically marked. {% else %}

              This question is abnormal

              -Answers marked as normal will be automatically marked. +Answers marked as normal will be automatically marked.
              Region: {{ question.get_regions }}, Abnormalities: {{ question.get_abnormalities }} {% endif %}