From 2ab972640774fd4f892737fb858dd84765f28612 Mon Sep 17 00:00:00 2001 From: Ross Date: Sat, 26 Jun 2021 11:33:18 +0100 Subject: [PATCH 01/53] . --- generic/views.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/generic/views.py b/generic/views.py index 1cb8878f..e6ba3610 100644 --- a/generic/views.py +++ b/generic/views.py @@ -406,6 +406,9 @@ class ExamViews(View, LoginRequiredMixin): if self.question_type == "long": h = {} for question in exam.exam_questions.all(): + # Generate json if needed + if question.json_creation_time is None: + question.get_json(question.pk) h[question.pk] = question.json_creation_time.isoformat() obj["multi_question_json"] = h active_exams["exams"].append( obj ) From ce5c7c62580971b31f32797b373d0aa8acabad2f Mon Sep 17 00:00:00 2001 From: Ross Date: Sat, 26 Jun 2021 12:17:32 +0100 Subject: [PATCH 02/53] . --- .gitignore | 1 + longs/models.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index d1b0b367..2222b2d1 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ __pycache__ .vscode/ .DS_Store rad/settings_local.py +.venv/ diff --git a/longs/models.py b/longs/models.py index 6312a505..bd8fed69 100644 --- a/longs/models.py +++ b/longs/models.py @@ -629,7 +629,7 @@ class Exam(ExamBase): if self.time_limit: exam_json["exam_time"] = self.time_limit - return exam_json + return "TEST" class CidUserAnswer(models.Model): """User answers by candidate""" From a8d396b1c60473d83a62d83eb5a03cb755721b4d Mon Sep 17 00:00:00 2001 From: Ross Date: Sat, 26 Jun 2021 12:21:35 +0100 Subject: [PATCH 03/53] . --- longs/models.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/longs/models.py b/longs/models.py index bd8fed69..bbcb648e 100644 --- a/longs/models.py +++ b/longs/models.py @@ -629,7 +629,9 @@ class Exam(ExamBase): if self.time_limit: exam_json["exam_time"] = self.time_limit - return "TEST" + exam_json["HELLO"] = "WORLD" + + return exam_json class CidUserAnswer(models.Model): """User answers by candidate""" From cb1ccdd3696a24e47f36e511b399453cab4eafdd Mon Sep 17 00:00:00 2001 From: Ross Date: Sat, 26 Jun 2021 12:22:23 +0100 Subject: [PATCH 04/53] . --- longs/models.py | 1 + 1 file changed, 1 insertion(+) diff --git a/longs/models.py b/longs/models.py index bbcb648e..d88d3c9b 100644 --- a/longs/models.py +++ b/longs/models.py @@ -619,6 +619,7 @@ class Exam(ExamBase): "exam_mode": True, "exam_order": exam_order, "questions": exam_questions, + "based": based, #"question_requests": exam_questions, } From a5ed0c6adea4735663974ba739b80be7677bc166 Mon Sep 17 00:00:00 2001 From: Ross Date: Sat, 26 Jun 2021 12:25:55 +0100 Subject: [PATCH 05/53] . --- longs/models.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/longs/models.py b/longs/models.py index d88d3c9b..3cda15f8 100644 --- a/longs/models.py +++ b/longs/models.py @@ -568,7 +568,7 @@ class Exam(ExamBase): return exam_question - def get_exam_json(self, based=False): + def get_exam_json(self, based=True): questions = self.exam_questions.all() exam_questions = defaultdict(dict) @@ -630,8 +630,6 @@ class Exam(ExamBase): if self.time_limit: exam_json["exam_time"] = self.time_limit - exam_json["HELLO"] = "WORLD" - return exam_json class CidUserAnswer(models.Model): From f2e499547ffc32392f8896921553d72b421b3c9c Mon Sep 17 00:00:00 2001 From: Ross Date: Sat, 26 Jun 2021 16:12:07 +0100 Subject: [PATCH 06/53] . --- rapids/models.py | 2 +- rapids/views.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/rapids/models.py b/rapids/models.py index 3cafa066..bbfa2bf7 100644 --- a/rapids/models.py +++ b/rapids/models.py @@ -419,13 +419,13 @@ class Exam(ExamBase): exam_questions[q.id] = { "images": images, - "normal": q.normal, #"feedback_image": [], #"annotations": [str(q.image_annotations)], "type": "rapid", } if not self.exam_mode: + exam_questions[q.id]["normal"] = q.normal exam_questions[q.id]["feedback_images"] = feedback_images exam_questions[q.id]["answers"] = list(q.GetCorrectUnstrippedAnswers()) diff --git a/rapids/views.py b/rapids/views.py index 9b87b875..d1ad0ac4 100755 --- a/rapids/views.py +++ b/rapids/views.py @@ -578,9 +578,9 @@ def loadJsonAnswer(answer): posted_answer = answer["ans"] - # qidn 1 does not hold answer data (but should always arrive prior to 2) - if answer["qidn"] == "1": - posted_answer = "" + ## qidn 1 does not hold answer data (but should always arrive prior to 2) + #if answer["qidn"] == "1": + # posted_answer = "" # Normal answers are just posted with the answer "Normal" normal = False From f02594bfd1777f6622375ea7ee800dafc425812b Mon Sep 17 00:00:00 2001 From: Ross Date: Sat, 26 Jun 2021 16:13:40 +0100 Subject: [PATCH 07/53] . --- rapids/views.py | 1 + 1 file changed, 1 insertion(+) diff --git a/rapids/views.py b/rapids/views.py index d1ad0ac4..bdab3b53 100755 --- a/rapids/views.py +++ b/rapids/views.py @@ -601,6 +601,7 @@ def loadJsonAnswer(answer): ans = exiting_answers[0] if answer["qidn"] == "1": ans.normal = normal + ans.answer = "" elif answer["qidn"] == "2": ans.answer = posted_answer ans.full_clean() From 410fae0d0d91ea30e8b1a5a36cb223f02f8ec128 Mon Sep 17 00:00:00 2001 From: Ross Date: Sat, 26 Jun 2021 16:15:54 +0100 Subject: [PATCH 08/53] . --- rapids/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rapids/views.py b/rapids/views.py index bdab3b53..4ddcb68b 100755 --- a/rapids/views.py +++ b/rapids/views.py @@ -602,7 +602,7 @@ def loadJsonAnswer(answer): if answer["qidn"] == "1": ans.normal = normal ans.answer = "" - elif answer["qidn"] == "2": + elif answer["qidn"] == "2" and not ans.normal: ans.answer = posted_answer ans.full_clean() ans.save() From 65d202a649748cd481199625cce35a51db141a68 Mon Sep 17 00:00:00 2001 From: Ross Date: Tue, 6 Jul 2021 19:57:15 +0100 Subject: [PATCH 09/53] . --- rapids/tables.py | 4 ++++ rapids/templates/rapids/ciduseranswer_detail.html | 8 ++++++++ rapids/templates/rapids/exam_overview.html | 4 +++- rapids/urls.py | 3 ++- rapids/views.py | 9 ++++++--- 5 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 rapids/templates/rapids/ciduseranswer_detail.html diff --git a/rapids/tables.py b/rapids/tables.py index a98ba283..c87e852f 100755 --- a/rapids/tables.py +++ b/rapids/tables.py @@ -62,6 +62,10 @@ class RapidUserAnswerTable(tables.Table): delete = tables.LinkColumn( "rapids:rapid_user_answer_delete", text="Delete", args=[A("pk")], orderable=False ) + view = tables.LinkColumn('rapids:rapid_user_answer_view', + text='View', + args=[A('pk')], + orderable=False) class Meta: model = CidUserAnswer template_name = "django_tables2/bootstrap4.html" diff --git a/rapids/templates/rapids/ciduseranswer_detail.html b/rapids/templates/rapids/ciduseranswer_detail.html new file mode 100644 index 00000000..f59bb2ed --- /dev/null +++ b/rapids/templates/rapids/ciduseranswer_detail.html @@ -0,0 +1,8 @@ + +{% extends 'rapids/base.html' %} + +{% block content %} +{{ciduseranswer.question}} +{{ciduseranswer.normal}} +{{ciduseranswer.cid}} +{% endblock content %} \ No newline at end of file diff --git a/rapids/templates/rapids/exam_overview.html b/rapids/templates/rapids/exam_overview.html index 1406608b..c35c1233 100644 --- a/rapids/templates/rapids/exam_overview.html +++ b/rapids/templates/rapids/exam_overview.html @@ -26,9 +26,11 @@ {% for question in questions.all %}
  • + {% for image in question.GetImages %} thumbail {% endfor %} + {% if not question.normal %} Abnormality: {{ question.get_abnormalities }} Region: {{ question.get_regions }}
    @@ -37,7 +39,7 @@ Normal {% endif %}
    - Examination: {{ question.get_examinations }}, View, Mark + Examination: {{ question.get_examinations }}, View, Mark
  • {% endfor %} diff --git a/rapids/urls.py b/rapids/urls.py index 3f123476..44ccbcec 100755 --- a/rapids/urls.py +++ b/rapids/urls.py @@ -66,6 +66,7 @@ urlpatterns = [ name="rapid_update", ), path("/add_note", views.AddNote.as_view(), name="rapid_add_note"), - path("user_answers/", views.RapidUserAnswerView.as_view(), name="rapid_user_answer_view"), + path("user_answers/", views.RapidUserAnswerTableView.as_view(), name="rapid_user_answer_table_view"), + path("user_answers/", views.RapidUserAnswerView.as_view(), name="rapid_user_answer_view"), path("user_answers//delete", views.UserAnswerDelete.as_view(), name="rapid_user_answer_delete"), ] diff --git a/rapids/views.py b/rapids/views.py index 4ddcb68b..fe85f80c 100755 --- a/rapids/views.py +++ b/rapids/views.py @@ -8,6 +8,7 @@ from django.contrib.auth.models import User from django.core.exceptions import PermissionDenied from django.contrib.auth.mixins import LoginRequiredMixin +from django.views.generic.detail import DetailView from django.views.generic.edit import CreateView, UpdateView, DeleteView from django.views.generic import ListView @@ -957,16 +958,18 @@ class ExamUpdate(RevisionMixin, LoginRequiredMixin, AuthorOrCheckerRequiredMixin form.instance.author.add(self.request.user.id) return super().form_valid(form) -class RapidUserAnswerView(LoginRequiredMixin, SingleTableMixin, FilterView): +class RapidUserAnswerView(LoginRequiredMixin, DetailView): + model = CidUserAnswer + +class RapidUserAnswerTableView(LoginRequiredMixin, SingleTableMixin, FilterView): model = CidUserAnswer table_class = RapidUserAnswerTable template_name = "rapids/rapid_question_view.html" filterset_class = RapidUserAnswerFilter - class UserAnswerDelete(SuperuserRequiredMixin, DeleteView): model = CidUserAnswer - success_url = reverse_lazy("rapids:rapid_user_answer_view") + success_url = reverse_lazy("rapids:rapid_user_answer_table_view") class LargeResultsSetPagination(PageNumberPagination): page_size = 1000 From e5a19130baf854eb1b34896493a91701fe43a2c8 Mon Sep 17 00:00:00 2001 From: Ross Date: Tue, 6 Jul 2021 20:02:35 +0100 Subject: [PATCH 10/53] . --- .../migrations/0040_alter_exam_exam_mode.py | 18 ++++++++++++++++++ anatomy/templates/anatomy/exam_overview.html | 4 +++- generic/models.py | 2 +- longs/migrations/0036_alter_exam_exam_mode.py | 18 ++++++++++++++++++ .../migrations/0008_alter_exam_exam_mode.py | 18 ++++++++++++++++++ rapids/migrations/0024_alter_exam_exam_mode.py | 18 ++++++++++++++++++ 6 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 anatomy/migrations/0040_alter_exam_exam_mode.py create mode 100644 longs/migrations/0036_alter_exam_exam_mode.py create mode 100644 physics/migrations/0008_alter_exam_exam_mode.py create mode 100644 rapids/migrations/0024_alter_exam_exam_mode.py diff --git a/anatomy/migrations/0040_alter_exam_exam_mode.py b/anatomy/migrations/0040_alter_exam_exam_mode.py new file mode 100644 index 00000000..cdef9e6c --- /dev/null +++ b/anatomy/migrations/0040_alter_exam_exam_mode.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.4 on 2021-07-06 19:02 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('anatomy', '0039_answer_proposed'), + ] + + operations = [ + migrations.AlterField( + model_name='exam', + name='exam_mode', + field=models.BooleanField(default=False, help_text='If an exam should be taken in exam mode (users results will be submited to the server for marking)'), + ), + ] diff --git a/anatomy/templates/anatomy/exam_overview.html b/anatomy/templates/anatomy/exam_overview.html index 842b3993..e67d588f 100644 --- a/anatomy/templates/anatomy/exam_overview.html +++ b/anatomy/templates/anatomy/exam_overview.html @@ -26,12 +26,14 @@ {% for question in questions.all %}
  • + thumbail + {{ question.description }}
    {{ question.question_type }}: {{ question.GetPrimaryAnswer }}
    - Modality: {{ question.modality }}, View, Mark + Modality: {{ question.modality }}, View, Mark
  • {% endfor %} diff --git a/generic/models.py b/generic/models.py index d662be79..186ed75e 100644 --- a/generic/models.py +++ b/generic/models.py @@ -61,7 +61,7 @@ class ExamBase(models.Model): ) exam_mode = models.BooleanField( - help_text="If an exam should be taken in exam mode", default=True + help_text="If an exam should be taken in exam mode (users results will be submited to the server for marking)", default=False ) publish_results = models.BooleanField( diff --git a/longs/migrations/0036_alter_exam_exam_mode.py b/longs/migrations/0036_alter_exam_exam_mode.py new file mode 100644 index 00000000..a7c64a12 --- /dev/null +++ b/longs/migrations/0036_alter_exam_exam_mode.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.4 on 2021-07-06 19:02 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('longs', '0035_longseries_open_access'), + ] + + operations = [ + migrations.AlterField( + model_name='exam', + name='exam_mode', + field=models.BooleanField(default=False, help_text='If an exam should be taken in exam mode (users results will be submited to the server for marking)'), + ), + ] diff --git a/physics/migrations/0008_alter_exam_exam_mode.py b/physics/migrations/0008_alter_exam_exam_mode.py new file mode 100644 index 00000000..4ff89b0f --- /dev/null +++ b/physics/migrations/0008_alter_exam_exam_mode.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.4 on 2021-07-06 19:02 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('physics', '0007_exam_author'), + ] + + operations = [ + migrations.AlterField( + model_name='exam', + name='exam_mode', + field=models.BooleanField(default=False, help_text='If an exam should be taken in exam mode (users results will be submited to the server for marking)'), + ), + ] diff --git a/rapids/migrations/0024_alter_exam_exam_mode.py b/rapids/migrations/0024_alter_exam_exam_mode.py new file mode 100644 index 00000000..1b502e5b --- /dev/null +++ b/rapids/migrations/0024_alter_exam_exam_mode.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.4 on 2021-07-06 19:02 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('rapids', '0023_answer_proposed'), + ] + + operations = [ + migrations.AlterField( + model_name='exam', + name='exam_mode', + field=models.BooleanField(default=False, help_text='If an exam should be taken in exam mode (users results will be submited to the server for marking)'), + ), + ] From c2888ca2378e4c4fe3ea0d9ddd1225db30809711 Mon Sep 17 00:00:00 2001 From: Ross Date: Wed, 7 Jul 2021 08:38:22 +0100 Subject: [PATCH 11/53] rename rapid functions --- anatomy/models.py | 22 ++++++------- anatomy/templates/anatomy/exam_overview.html | 2 +- anatomy/templates/anatomy/mark_overview.html | 4 +-- .../templates/anatomy/question_detail.html | 2 +- anatomy/views.py | 4 +-- generic/models.py | 2 +- .../migrations/0037_alter_exam_time_limit.py | 18 +++++++++++ longs/models.py | 16 +++++----- longs/templates/longs/long_display_block.html | 2 +- longs/templates/longs/mark_overview.html | 4 +-- longs/views.py | 2 +- rapids/models.py | 32 +++++++++---------- rapids/templates/rapids/exam_overview.html | 4 +-- rapids/templates/rapids/mark.html | 2 +- rapids/templates/rapids/mark_overview.html | 4 +-- .../rapids/question_display_block.html | 2 +- rapids/views.py | 4 +-- 17 files changed, 72 insertions(+), 54 deletions(-) create mode 100644 longs/migrations/0037_alter_exam_time_limit.py diff --git a/anatomy/models.py b/anatomy/models.py index 09daeb86..0cd9837f 100644 --- a/anatomy/models.py +++ b/anatomy/models.py @@ -130,7 +130,7 @@ class AnatomyQuestion(models.Model): def __str__(self): # Get first answer return "{} [{}, {}]".format( - self.GetPrimaryAnswer(), self.modality, self.structure + self.get_primary_answer(), self.modality, self.structure ) # Get associated exams e = self.exams.all().values_list("name", flat=True) @@ -146,19 +146,19 @@ class AnatomyQuestion(models.Model): def get_absolute_url(self): return reverse("anatomy:question_detail", kwargs={"pk": self.pk}) - def GetPrimaryAnswer(self): + def get_primary_answer(self): if len(self.answers.filter(proposed=False)) > 0: return self.answers.filter(proposed=False).first().answer else: return "None yet..." - def GetExams(self): + def get_exams(self): e = self.exams.all().values_list("name", flat=True) exams = ", ".join(e) return exams - def GetUnmarkedAnswersString(self): - unmarked_answers = self.GetUnmarkedAnswers() + def get_unmarked_answer_string(self): + unmarked_answers = self.get_unmarked_answers() if not unmarked_answers: return "No answers to mark" @@ -168,18 +168,18 @@ class AnatomyQuestion(models.Model): ) ) - def GetUnmarkedAnswers(self): + def get_unmarked_answers(self): user_answers = set( [i.answer_compare for i in self.cid_user_answers.all()] ) - unmarked_answers = user_answers - self.GetMarkedAnswers() + unmarked_answers = user_answers - self.get_marked_answers() return unmarked_answers - def GetUnmarkedAnswerCount(self): - return len(self.GetUnmarkedAnswers()) + def get_unmarked_answer_count(self): + return len(self.get_unmarked_answers()) - def GetMarkedAnswers(self): + def get_marked_answers(self): return set( [ i.answer_compare @@ -350,7 +350,7 @@ class CidUserAnswer(models.Model): except (Exam.DoesNotExist, KeyError) as e: exam = "None" return "{}/{}/{}: {}".format( - exam, self.cid, self.question.GetPrimaryAnswer(), self.answer + exam, self.cid, self.question.get_primary_answer(), self.answer ) def save(self, *args, **kwargs): diff --git a/anatomy/templates/anatomy/exam_overview.html b/anatomy/templates/anatomy/exam_overview.html index e67d588f..44ac9132 100644 --- a/anatomy/templates/anatomy/exam_overview.html +++ b/anatomy/templates/anatomy/exam_overview.html @@ -31,7 +31,7 @@ {{ question.description }}
    - {{ question.question_type }}: {{ question.GetPrimaryAnswer }} + {{ question.question_type }}: {{ question.get_primary_answer }}
    Modality: {{ question.modality }}, View, Mark diff --git a/anatomy/templates/anatomy/mark_overview.html b/anatomy/templates/anatomy/mark_overview.html index ed2619b4..95afc5bd 100644 --- a/anatomy/templates/anatomy/mark_overview.html +++ b/anatomy/templates/anatomy/mark_overview.html @@ -12,8 +12,8 @@ diff --git a/anatomy/templates/anatomy/question_detail.html b/anatomy/templates/anatomy/question_detail.html index 0f49631a..51c23cff 100644 --- a/anatomy/templates/anatomy/question_detail.html +++ b/anatomy/templates/anatomy/question_detail.html @@ -29,7 +29,7 @@
    Created: {{ question.created_date }}
    -

    {{ question.GetPrimaryAnswer }}

    +

    {{ question.get_primary_answer }}

    {{question.question_type}}

    Answers (score): {% for answer in question.answers.all %} {{ answer }} ({{answer.status}}), diff --git a/anatomy/views.py b/anatomy/views.py index 98edc7de..8778bbc9 100644 --- a/anatomy/views.py +++ b/anatomy/views.py @@ -333,7 +333,7 @@ def mark(request, pk, sk): # i.answer.lower() for i in question.incorrect_answers.all() # ] - unmarked_user_answers = question.GetUnmarkedAnswers() + unmarked_user_answers = question.get_unmarked_answers() if request.method == "POST": @@ -576,7 +576,7 @@ def exam_scores_cid_user(request, pk, sk): answer_score = user_answer.get_answer_score() - correct_answer = q.GetPrimaryAnswer() + correct_answer = q.get_primary_answer() if not exam.publish_results: correct_answer = "*****" diff --git a/generic/models.py b/generic/models.py index 186ed75e..af9b5e48 100644 --- a/generic/models.py +++ b/generic/models.py @@ -53,7 +53,7 @@ class Sign(tagulous.models.TagModel): class ExamBase(models.Model): - name = models.CharField(max_length=200) + name = models.CharField(max_length=200, help_text="Name of the exam") #exam_questions = SortedManyToManyField(Long, related_name="exams", blank="true") active = models.BooleanField( diff --git a/longs/migrations/0037_alter_exam_time_limit.py b/longs/migrations/0037_alter_exam_time_limit.py new file mode 100644 index 00000000..ec3ad674 --- /dev/null +++ b/longs/migrations/0037_alter_exam_time_limit.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.4 on 2021-07-06 19:03 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('longs', '0036_alter_exam_exam_mode'), + ] + + operations = [ + migrations.AlterField( + model_name='exam', + name='time_limit', + field=models.IntegerField(default=4500, help_text='Exam time limit (in seconds). Default is 4500 seconds (75 minutes)'), + ), + ] diff --git a/longs/models.py b/longs/models.py index 3cda15f8..1f030da7 100644 --- a/longs/models.py +++ b/longs/models.py @@ -145,12 +145,12 @@ class Long(models.Model): examinations = [series.get_examination() for series in self.series.all()] return "{} : {}".format(self.description, ", ".join(examinations)) - def GetExams(self): + def get_exams(self): e = self.exams.all().values_list("name", flat=True) exams = ", ".join(e) return exams - def GetImages(self, feedback=False): + def get_images(self, feedback=False): qs = self.images.all() if not feedback: @@ -160,16 +160,16 @@ class Long(models.Model): return images - def GetImageUrls(self): + def get_image_urls(self): return ",".join( - ["https://penracourses.org.uk{}".format(i.url) for i in self.GetImages()] + ["https://penracourses.org.uk{}".format(i.url) for i in self.get_images()] ) - def GetUnmarkedAnswerCount(self): + def get_unmarked_answer_count(self): answers = self.cid_user_answers.all() return len([ans for ans in answers if not ans.is_marked()]) - def GetUnmarkedAnswers(self): + def get_unmarked_answers(self): answers = self.cid_user_answers.all() return [ans for ans in answers if not ans.is_marked()] @@ -266,7 +266,7 @@ class Long(models.Model): # def GetNonFeedbackQuestionImages(self): - # return self.GetImages() + # return self.get_images() def test_image_validator(file): @@ -527,7 +527,7 @@ class Exam(ExamBase): exam_questions = SortedManyToManyField(Long, related_name="exams", blank="true") time_limit = models.IntegerField( - help_text="Exam time limit (in seconds). Default is 4500 secondse (75 minutes)", + help_text="Exam time limit (in seconds). Default is 4500 seconds (75 minutes)", default=4500, ) diff --git a/longs/templates/longs/long_display_block.html b/longs/templates/longs/long_display_block.html index 49771d4b..68f48bbc 100755 --- a/longs/templates/longs/long_display_block.html +++ b/longs/templates/longs/long_display_block.html @@ -40,7 +40,7 @@

    Mark Scheme:

    {{ question.mark_scheme }}

    -

    Exam(s): {{question.GetExams}}

    +

    Exam(s): {{question.get_exams}}

    Notes: diff --git a/longs/templates/longs/mark_overview.html b/longs/templates/longs/mark_overview.html index 3c27e55a..da27deb5 100644 --- a/longs/templates/longs/mark_overview.html +++ b/longs/templates/longs/mark_overview.html @@ -12,8 +12,8 @@
    diff --git a/longs/views.py b/longs/views.py index ec73369c..90b3cd07 100755 --- a/longs/views.py +++ b/longs/views.py @@ -655,7 +655,7 @@ def mark_answer(request, pk, sk, tk): raise Http404("User answer does not exist") try: - unmarked = question.GetUnmarkedAnswers() + unmarked = question.get_unmarked_answers() next_unmarked_id = unmarked[0].cid if next_unmarked_id == tk: next_unmarked_id = unmarked[1].cid diff --git a/rapids/models.py b/rapids/models.py index bbfa2bf7..05ce8014 100644 --- a/rapids/models.py +++ b/rapids/models.py @@ -216,7 +216,7 @@ class Rapid(models.Model): lat = self.laterality return "{} / {} {}".format(exams, lat, n) - def GetPrimaryAnswer(self): + def get_primary_answer(self): if self.normal: return "Normal" elif len(self.answers.filter(proposed=False)) > 0: @@ -224,13 +224,13 @@ class Rapid(models.Model): else: return "None yet..." - def GetExams(self): + def get_exams(self): e = self.exams.all().values_list("name", flat=True) exams = ", ".join(e) return exams - def GetUnmarkedAnswersString(self): - unmarked_answers = self.GetUnmarkedAnswers() + def get_unmarked_answer_string(self): + unmarked_answers = self.get_unmarked_answers() if not unmarked_answers: return "No answers to mark" @@ -240,7 +240,7 @@ class Rapid(models.Model): ) ) - def GetUnmarkedAnswers(self): + def get_unmarked_answers(self): # If normal no answers to mark if self.normal: return [] @@ -248,14 +248,14 @@ class Rapid(models.Model): user_answers = set( [i.answer_compare for i in self.cid_user_answers.all() if i.normal == False] ) - unmarked_answers = user_answers - self.GetMarkedAnswers() + unmarked_answers = user_answers - self.get_marked_answers() return unmarked_answers - def GetUnmarkedAnswerCount(self): - return len(self.GetUnmarkedAnswers()) + def get_unmarked_answer_count(self): + return len(self.get_unmarked_answers()) - def GetMarkedAnswers(self): + def get_marked_answers(self): return set( [ i.answer_compare @@ -276,7 +276,7 @@ class Rapid(models.Model): marked_answers = correct_answers | half_mark_answers | incorrect_answers return marked_answers - def GetCorrectUnstrippedAnswers(self): + def get_correct_unstripped_answers(self): return set( [ str(i) @@ -285,7 +285,7 @@ class Rapid(models.Model): ] ) - def GetImages(self, feedback=False): + def get_images(self, feedback=False): qs = self.images.all() if not feedback: @@ -295,10 +295,10 @@ class Rapid(models.Model): return images - def GetImageUrls(self): - return ",".join(["https://penracourses.org.uk{}".format(i.url) for i in self.GetImages()]) + def get_image_urls(self): + return ",".join(["https://penracourses.org.uk{}".format(i.url) for i in self.get_images()]) #def GetNonFeedbackQuestionImages(self): - #return self.GetImages() + #return self.get_images() class RapidImage(models.Model): @@ -427,7 +427,7 @@ class Exam(ExamBase): if not self.exam_mode: exam_questions[q.id]["normal"] = q.normal exam_questions[q.id]["feedback_images"] = feedback_images - exam_questions[q.id]["answers"] = list(q.GetCorrectUnstrippedAnswers()) + exam_questions[q.id]["answers"] = list(q.get_correct_unstripped_answers()) #if feedback_images: @@ -482,7 +482,7 @@ class CidUserAnswer(models.Model): except (Exam.DoesNotExist, KeyError) as e: exam = "None" return "{}/{}/{}: {}".format( - exam, self.cid, self.question.GetPrimaryAnswer(), self.answer + exam, self.cid, self.question.get_primary_answer(), self.answer ) def save(self, *args, **kwargs): diff --git a/rapids/templates/rapids/exam_overview.html b/rapids/templates/rapids/exam_overview.html index c35c1233..d4f1407f 100644 --- a/rapids/templates/rapids/exam_overview.html +++ b/rapids/templates/rapids/exam_overview.html @@ -27,14 +27,14 @@
  • - {% for image in question.GetImages %} + {% for image in question.get_images %} thumbail {% endfor %} {% if not question.normal %} Abnormality: {{ question.get_abnormalities }} Region: {{ question.get_regions }}
    - {{ question.GetPrimaryAnswer }} + {{ question.get_primary_answer }} {% else %} Normal {% endif %} diff --git a/rapids/templates/rapids/mark.html b/rapids/templates/rapids/mark.html index 0cf37d5f..b063b23a 100644 --- a/rapids/templates/rapids/mark.html +++ b/rapids/templates/rapids/mark.html @@ -13,7 +13,7 @@ Answers will be automatically marked. Answers marked as normal will be automatically marked.
    Region: {{ question.get_regions }}, Abnormalities: {{ question.get_abnormalities }} {% endif %} -
    diff --git a/rapids/templates/rapids/mark_overview.html b/rapids/templates/rapids/mark_overview.html index 37849233..f6bc4ed1 100644 --- a/rapids/templates/rapids/mark_overview.html +++ b/rapids/templates/rapids/mark_overview.html @@ -12,8 +12,8 @@
    diff --git a/rapids/templates/rapids/question_display_block.html b/rapids/templates/rapids/question_display_block.html index fc84ef9d..0b2eab14 100755 --- a/rapids/templates/rapids/question_display_block.html +++ b/rapids/templates/rapids/question_display_block.html @@ -60,7 +60,7 @@ {% endif %} -
    +
    \ No newline at end of file + // send request to change the is_private state on customSwitches toggle + $(".proposed-answer").each((n, el) => { + + // Add button to confirm answer is correct + $(el).append($("[Correct]").on("click", function () { + $.ajax({ + url: "{% url 'answer_suggestion_confirm' %}", + data: { + csrfmiddlewaretoken: "{{ csrf_token }}", + //active: this.checked // true if checked else false + question_type: "rapid", + aid: el.dataset.aid, + status: 2, + }, + type: "POST", + dataType: "json", + }) + // $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly + .done(function (data) { + console.log(data); + + if (data.success) { + toastr.info('Answer saved') + $(el).find(".confirm").remove() + $(el).removeClass("proposed-answer") + } + // show some message according to the response. + // For eg. A message box showing that the status has been changed + }) + .always(function () { + console.log('[Done]'); + }) + })) + + // Add button to confirm answer is incorrect + $(el).append($("[Incorrect]").on("click", function () { + $.ajax({ + url: "{% url 'answer_suggestion_confirm' %}", + data: { + csrfmiddlewaretoken: "{{ csrf_token }}", + //active: this.checked // true if checked else false + question_type: "rapid", + aid: el.dataset.aid, + status: 0, + }, + type: "POST", + dataType: "json", + }) + // $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly + .done(function (data) { + console.log(data); + + if (data.success) { + toastr.info('Answer saved') + $(el).find(".confirm").remove() + $(el).removeClass("proposed-answer") + } + // show some message according to the response. + // For eg. A message box showing that the status has been changed + }) + .always(function () { + console.log('[Done]'); + }) + })) + }); + }); + + \ No newline at end of file From 8c1c655b875445cec0f2ae1a4342773816cf50c6 Mon Sep 17 00:00:00 2001 From: Ross Date: Wed, 7 Jul 2021 17:10:31 +0100 Subject: [PATCH 17/53] . --- rapids/templates/rapids/question_display_block.html | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/rapids/templates/rapids/question_display_block.html b/rapids/templates/rapids/question_display_block.html index a09ce9b6..228477e3 100755 --- a/rapids/templates/rapids/question_display_block.html +++ b/rapids/templates/rapids/question_display_block.html @@ -31,8 +31,7 @@

    Scrapped: {{ question.scrapped }} (toggle)

    Answers (score): {% for answer in question.answers.all %} - + {{ answer }} ({{answer.status}}), {% endfor %} From 1bfb480f52fcef9f7768b3a42bc3f89e017aea24 Mon Sep 17 00:00:00 2001 From: Ross Date: Wed, 7 Jul 2021 17:14:02 +0100 Subject: [PATCH 18/53] . --- rad/views.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/rad/views.py b/rad/views.py index 1ae8df0e..ca9a57d1 100644 --- a/rad/views.py +++ b/rad/views.py @@ -251,11 +251,10 @@ def answer_suggestion_submit(request): @login_required def answer_submit(request): if request.is_ajax and request.method == "POST": - post_data = json.loads(request.body) - qid = post_data["qid"] - question_type = post_data["question_type"] - answer_string = post_data["answer"] - status = post_data["status"] + qid = request.POST.get("qid") + question_type = request.POST.get("question_type") + answer_string = request.POST.get("answer") + status = request.POST.get("status") if str(status) not in "012": return JsonResponse({"success": False, "error": "Invalid status"}) From d40fec3e6a14a9fb7ea33891af12c3addcceb611 Mon Sep 17 00:00:00 2001 From: Ross Date: Wed, 7 Jul 2021 18:04:05 +0100 Subject: [PATCH 19/53] . --- rad/views.py | 1 + rapids/templates/rapids/question_display_block.html | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/rad/views.py b/rad/views.py index ca9a57d1..2b858214 100644 --- a/rad/views.py +++ b/rad/views.py @@ -275,6 +275,7 @@ def answer_submit(request): a = AnswerModel(question=q, answer=answer_string, status=status) a.save() + return JsonResponse({"success": True, "error": "Answer added"}) return JsonResponse({"success": False, "error": "Invalid data"}) diff --git a/rapids/templates/rapids/question_display_block.html b/rapids/templates/rapids/question_display_block.html index 228477e3..7e486896 100755 --- a/rapids/templates/rapids/question_display_block.html +++ b/rapids/templates/rapids/question_display_block.html @@ -121,7 +121,7 @@ $(".proposed-answer").each((n, el) => { // Add button to confirm answer is correct - $(el).append($("[Correct]").on("click", function () { + $(el).append($("[Add Correct]").on("click", function () { $.ajax({ url: "{% url 'answer_suggestion_confirm' %}", data: { @@ -139,9 +139,8 @@ console.log(data); if (data.success) { - toastr.info('Answer saved') - $(el).find(".confirm").remove() - $(el).removeClass("proposed-answer") + toastr.info('Answer added') + $(el).find(".correct").remove() } // show some message according to the response. // For eg. A message box showing that the status has been changed From 5181e4e20e967db8852cfc97318bc0bf40122e5d Mon Sep 17 00:00:00 2001 From: Ross Date: Wed, 7 Jul 2021 18:11:30 +0100 Subject: [PATCH 20/53] . --- rapids/models.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/rapids/models.py b/rapids/models.py index b76ebd0b..f29c6934 100644 --- a/rapids/models.py +++ b/rapids/models.py @@ -307,12 +307,25 @@ class Rapid(models.Model): #def GetNonFeedbackQuestionImages(self): #return self.get_images() + def get_laterality_string(self): + if self.laterality == self.NONE: + s = "" + elif self.laterality == self.BILATERAL: + s = "bilateral " + elif self.laterality == self.RIGHT: + s = "right " + elif self.laterality == self.LEFT: + s = "left " + + return s + def get_suggested_answers(self): answers = [] for r in self.region.all(): + laterality = self.get_laterality_string() for a in self.abnormality.all(): - answers.append("{} {}".format(r.name, a.name)) - answers.append("{} {}".format(a.name, r.name)) + answers.append("{}{} {}".format(laterality, r.name, a.name)) + answers.append("{} {}{}".format(a.name, laterality, r.name)) compare_answers = self.get_compare_answers() From 2c76fd7156fc168e9b0d7f646159269f93489a20 Mon Sep 17 00:00:00 2001 From: Ross Date: Wed, 7 Jul 2021 18:13:52 +0100 Subject: [PATCH 21/53] . --- rapids/templates/rapids/question_display_block.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rapids/templates/rapids/question_display_block.html b/rapids/templates/rapids/question_display_block.html index 7e486896..8e177e5b 100755 --- a/rapids/templates/rapids/question_display_block.html +++ b/rapids/templates/rapids/question_display_block.html @@ -84,7 +84,7 @@ $(document).ready(function () { $(".suggested_answers li").each((n, el) => { - $(el).append($("[Correct]").on("click", function () { + $(el).append($("[Add Correct]").on("click", function () { $.ajax({ url: "{% url 'answer_submit' %}", data: { @@ -105,7 +105,6 @@ if (data.success) { toastr.info('Answer saved') $(el).find(".confirm").remove() - $(el).removeClass("proposed-answer") } // show some message according to the response. // For eg. A message box showing that the status has been changed @@ -139,8 +138,9 @@ console.log(data); if (data.success) { - toastr.info('Answer added') + toastr.info('Answer saved') $(el).find(".correct").remove() + $(el).removeClass("proposed-answer") } // show some message according to the response. // For eg. A message box showing that the status has been changed From fafe5eccaf27dcf3ac4b65b85907ad0a6a470218 Mon Sep 17 00:00:00 2001 From: Ross Date: Wed, 7 Jul 2021 18:14:26 +0100 Subject: [PATCH 22/53] . --- rapids/templates/rapids/question_display_block.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rapids/templates/rapids/question_display_block.html b/rapids/templates/rapids/question_display_block.html index 8e177e5b..742415d5 100755 --- a/rapids/templates/rapids/question_display_block.html +++ b/rapids/templates/rapids/question_display_block.html @@ -84,7 +84,7 @@ $(document).ready(function () { $(".suggested_answers li").each((n, el) => { - $(el).append($("[Add Correct]").on("click", function () { + $(el).append($("[Add Correct]").on("click", function () { $.ajax({ url: "{% url 'answer_submit' %}", data: { @@ -104,7 +104,7 @@ if (data.success) { toastr.info('Answer saved') - $(el).find(".confirm").remove() + $(el).find(".correct").remove() } // show some message according to the response. // For eg. A message box showing that the status has been changed @@ -120,7 +120,7 @@ $(".proposed-answer").each((n, el) => { // Add button to confirm answer is correct - $(el).append($("[Add Correct]").on("click", function () { + $(el).append($("[Add Correct]").on("click", function () { $.ajax({ url: "{% url 'answer_suggestion_confirm' %}", data: { @@ -139,7 +139,7 @@ if (data.success) { toastr.info('Answer saved') - $(el).find(".correct").remove() + $(el).find(".confirm").remove() $(el).removeClass("proposed-answer") } // show some message according to the response. From aca4c7fa2871a3068bf009f5b4d0845472a94f64 Mon Sep 17 00:00:00 2001 From: Ross Date: Thu, 8 Jul 2021 14:44:36 +0100 Subject: [PATCH 23/53] . --- rapids/models.py | 2 + .../rapids/question_display_block.html | 203 +++++++++--------- 2 files changed, 104 insertions(+), 101 deletions(-) diff --git a/rapids/models.py b/rapids/models.py index f29c6934..65542bd9 100644 --- a/rapids/models.py +++ b/rapids/models.py @@ -326,6 +326,8 @@ class Rapid(models.Model): for a in self.abnormality.all(): answers.append("{}{} {}".format(laterality, r.name, a.name)) answers.append("{} {}{}".format(a.name, laterality, r.name)) + answers.append("{} {}".format(r.name, a.name)) + answers.append("{} {}".format(a.name, r.name)) compare_answers = self.get_compare_answers() diff --git a/rapids/templates/rapids/question_display_block.html b/rapids/templates/rapids/question_display_block.html index 742415d5..ae01fe14 100755 --- a/rapids/templates/rapids/question_display_block.html +++ b/rapids/templates/rapids/question_display_block.html @@ -31,7 +31,8 @@

    Scrapped: {{ question.scrapped }} (toggle)

    Answers (score): {% for answer in question.answers.all %} - + {{ answer }} ({{answer.status}}), {% endfor %} @@ -69,8 +70,8 @@

  • {{ans}}
  • {% endfor %} + -
    @@ -78,109 +79,109 @@
    - +
    - \ No newline at end of file + // send request to change the is_private state on customSwitches toggle + $(".proposed-answer").each((n, el) => { + + // Add button to confirm answer is correct + $(el).append($("[Add Correct]").on("click", function () { + $.ajax({ + url: "{% url 'answer_suggestion_confirm' %}", + data: { + csrfmiddlewaretoken: "{{ csrf_token }}", + //active: this.checked // true if checked else false + question_type: "rapid", + aid: el.dataset.aid, + status: 2, + }, + type: "POST", + dataType: "json", + }) + // $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly + .done(function (data) { + console.log(data); + + if (data.success) { + toastr.info('Answer saved') + $(el).find(".confirm").remove() + $(el).removeClass("proposed-answer") + } + // show some message according to the response. + // For eg. A message box showing that the status has been changed + }) + .always(function () { + console.log('[Done]'); + }) + })) + + // Add button to confirm answer is incorrect + $(el).append($("[Incorrect]").on("click", function () { + $.ajax({ + url: "{% url 'answer_suggestion_confirm' %}", + data: { + csrfmiddlewaretoken: "{{ csrf_token }}", + //active: this.checked // true if checked else false + question_type: "rapid", + aid: el.dataset.aid, + status: 0, + }, + type: "POST", + dataType: "json", + }) + // $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly + .done(function (data) { + console.log(data); + + if (data.success) { + toastr.info('Answer saved') + $(el).find(".confirm").remove() + $(el).removeClass("proposed-answer") + } + // show some message according to the response. + // For eg. A message box showing that the status has been changed + }) + .always(function () { + console.log('[Done]'); + }) + })) + }); + }); + + \ No newline at end of file From d3139baba7896a76cb2e83376b6d31b94ae38150 Mon Sep 17 00:00:00 2001 From: Ross Date: Thu, 8 Jul 2021 14:52:56 +0100 Subject: [PATCH 24/53] . --- .../rapids/question_display_block.html | 85 +++++++++---------- 1 file changed, 42 insertions(+), 43 deletions(-) diff --git a/rapids/templates/rapids/question_display_block.html b/rapids/templates/rapids/question_display_block.html index ae01fe14..65e0d003 100755 --- a/rapids/templates/rapids/question_display_block.html +++ b/rapids/templates/rapids/question_display_block.html @@ -29,14 +29,14 @@

    Checked by: {% for verified in question.verified.all %} {{verified}}, {% endfor %}

    Scrapped: {{ question.scrapped }} (toggle) -

    - Answers (score): {% for answer in question.answers.all %} - - {{ answer }} ({{answer.status}}), - - {% endfor %} -

    +

    + Answers (score): {% for answer in question.answers.all %} + + {{ answer }} ({{answer.status}}), + + {% endfor %} +

    @@ -87,18 +87,18 @@ $(".suggested_answers li").each((n, el) => { $(el).append($("[Add Correct]").on("click", function () { $.ajax({ - url: "{% url 'answer_submit' %}", - data: { - csrfmiddlewaretoken: "{{ csrf_token }}", - //active: this.checked // true if checked else false - question_type: "rapid", - qid: "{{question.pk}}", - status: 2, - answer: el.dataset.string, - }, - type: "POST", - dataType: "json", - }) + url: "{% url 'answer_submit' %}", + data: { + csrfmiddlewaretoken: "{{ csrf_token }}", + //active: this.checked // true if checked else false + question_type: "rapid", + qid: "{{question.pk}}", + status: 2, + answer: el.dataset.string, + }, + type: "POST", + dataType: "json", + }) // $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly .done(function (data) { console.log(data); @@ -123,17 +123,17 @@ // Add button to confirm answer is correct $(el).append($("[Add Correct]").on("click", function () { $.ajax({ - url: "{% url 'answer_suggestion_confirm' %}", - data: { - csrfmiddlewaretoken: "{{ csrf_token }}", - //active: this.checked // true if checked else false - question_type: "rapid", - aid: el.dataset.aid, - status: 2, - }, - type: "POST", - dataType: "json", - }) + url: "{% url 'answer_suggestion_confirm' %}", + data: { + csrfmiddlewaretoken: "{{ csrf_token }}", + //active: this.checked // true if checked else false + question_type: "rapid", + aid: el.dataset.aid, + status: 2, + }, + type: "POST", + dataType: "json", + }) // $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly .done(function (data) { console.log(data); @@ -154,17 +154,17 @@ // Add button to confirm answer is incorrect $(el).append($("[Incorrect]").on("click", function () { $.ajax({ - url: "{% url 'answer_suggestion_confirm' %}", - data: { - csrfmiddlewaretoken: "{{ csrf_token }}", - //active: this.checked // true if checked else false - question_type: "rapid", - aid: el.dataset.aid, - status: 0, - }, - type: "POST", - dataType: "json", - }) + url: "{% url 'answer_suggestion_confirm' %}", + data: { + csrfmiddlewaretoken: "{{ csrf_token }}", + //active: this.checked // true if checked else false + question_type: "rapid", + aid: el.dataset.aid, + status: 0, + }, + type: "POST", + dataType: "json", + }) // $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly .done(function (data) { console.log(data); @@ -183,5 +183,4 @@ })) }); }); - \ No newline at end of file From 2b7751c6c1e4270c9406a9e6a2da2018d0c8c8c4 Mon Sep 17 00:00:00 2001 From: Ross Date: Thu, 8 Jul 2021 14:54:34 +0100 Subject: [PATCH 25/53] . --- rapids/templates/rapids/question_display_block.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rapids/templates/rapids/question_display_block.html b/rapids/templates/rapids/question_display_block.html index 65e0d003..9336c827 100755 --- a/rapids/templates/rapids/question_display_block.html +++ b/rapids/templates/rapids/question_display_block.html @@ -77,9 +77,9 @@

    Image viewer

    +
    - \ No newline at end of file + + // send request to change the is_private state on customSwitches toggle + $(".proposed-answer").each((n, el) => { + + // Add button to confirm answer is correct + $(el).append($("[Add Correct]").on("click", function () { + $.ajax({ + url: "{% url 'answer_suggestion_confirm' %}", + data: { + csrfmiddlewaretoken: "{{ csrf_token }}", + //active: this.checked // true if checked else false + question_type: "rapid", + aid: el.dataset.aid, + status: 2, + }, + type: "POST", + dataType: "json", + }) + // $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly + .done(function (data) { + console.log(data); + + if (data.success) { + toastr.info('Answer saved') + $(el).find(".confirm").remove() + $(el).removeClass("proposed-answer") + } + // show some message according to the response. + // For eg. A message box showing that the status has been changed + }) + .always(function () { + console.log('[Done]'); + }) + })) + + // Add button to confirm answer is incorrect + $(el).append($("[Incorrect]").on("click", function () { + $.ajax({ + url: "{% url 'answer_suggestion_confirm' %}", + data: { + csrfmiddlewaretoken: "{{ csrf_token }}", + //active: this.checked // true if checked else false + question_type: "rapid", + aid: el.dataset.aid, + status: 0, + }, + type: "POST", + dataType: "json", + }) + // $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly + .done(function (data) { + console.log(data); + + if (data.success) { + toastr.info('Answer saved') + $(el).find(".confirm").remove() + $(el).removeClass("proposed-answer") + } + // show some message according to the response. + // For eg. A message box showing that the status has been changed + }) + .always(function () { + console.log('[Done]'); + }) + })) + }); + }); + + \ No newline at end of file From fb2aa07b174ac2bb53796be9117ea9b828bde8c1 Mon Sep 17 00:00:00 2001 From: Ross Date: Thu, 8 Jul 2021 16:35:49 +0100 Subject: [PATCH 43/53] . --- .../rapids/question_display_block.html | 224 +++++++++--------- 1 file changed, 112 insertions(+), 112 deletions(-) diff --git a/rapids/templates/rapids/question_display_block.html b/rapids/templates/rapids/question_display_block.html index 19b368f5..38154a6a 100755 --- a/rapids/templates/rapids/question_display_block.html +++ b/rapids/templates/rapids/question_display_block.html @@ -92,127 +92,126 @@ /* beautify ignore:end */ $("#toggle-normal-button").click(function () { - $.ajax({ - url: "{% url 'rapid-detail' question.id %}", - type: 'PATCH', - headers: { - "X-CSRFToken": "{{ csrf_token }}" - }, - timeout: 3000, - data: { - csrfmiddlewaretoken: "{{ csrf_token }}", - normal: n, - } - }) - .done(function (data) { - console.log(data); - toastr.info('Answer saved') - } - }) - .fail(function () { - alert('Error updating this model instance.'); - //chk_status_field.prop('checked', !chk_status_field.prop('checked')); - }); + $.ajax({ + url: "{% url 'rapid-detail' question.id %}", + type: 'PATCH', + headers: { + "X-CSRFToken": "{{ csrf_token }}" + }, + timeout: 3000, + data: { + csrfmiddlewaretoken: "{{ csrf_token }}", + normal: n, + } + }) + .done(function (data) { + console.log(data); + toastr.info('Answer saved') + }) + .fail(function () { + alert('Error updating this model instance.'); + //chk_status_field.prop('checked', !chk_status_field.prop('checked')); + }); }); - $(".suggested_answers li").each((n, el) => { - $(el).append($("[Add Correct]").on("click", function () { - $.ajax({ - url: "{% url 'answer_submit' %}", - data: { - csrfmiddlewaretoken: "{{ csrf_token }}", - //active: this.checked // true if checked else false - question_type: "rapid", - qid: "{{question.pk}}", - status: 2, - answer: el.dataset.string, - }, - type: "POST", - dataType: "json", - }) - // $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly - .done(function (data) { - console.log(data); + $(".suggested_answers li").each((n, el) => { + $(el).append($("[Add Correct]").on("click", function () { + $.ajax({ + url: "{% url 'answer_submit' %}", + data: { + csrfmiddlewaretoken: "{{ csrf_token }}", + //active: this.checked // true if checked else false + question_type: "rapid", + qid: "{{question.pk}}", + status: 2, + answer: el.dataset.string, + }, + type: "POST", + dataType: "json", + }) + // $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly + .done(function (data) { + console.log(data); - if (data.success) { - toastr.info('Answer saved') - $(el).find(".correct").remove() - } - // show some message according to the response. - // For eg. A message box showing that the status has been changed - }) - .always(function () { - console.log('[Done]'); - }) - })) + if (data.success) { + toastr.info('Answer saved') + $(el).find(".correct").remove() + } + // show some message according to the response. + // For eg. A message box showing that the status has been changed + }) + .always(function () { + console.log('[Done]'); + }) + })) - }); + }); - // send request to change the is_private state on customSwitches toggle - $(".proposed-answer").each((n, el) => { + // send request to change the is_private state on customSwitches toggle + $(".proposed-answer").each((n, el) => { - // Add button to confirm answer is correct - $(el).append($("[Add Correct]").on("click", function () { - $.ajax({ - url: "{% url 'answer_suggestion_confirm' %}", - data: { - csrfmiddlewaretoken: "{{ csrf_token }}", - //active: this.checked // true if checked else false - question_type: "rapid", - aid: el.dataset.aid, - status: 2, - }, - type: "POST", - dataType: "json", - }) - // $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly - .done(function (data) { - console.log(data); + // Add button to confirm answer is correct + $(el).append($("[Add Correct]").on("click", function () { + $.ajax({ + url: "{% url 'answer_suggestion_confirm' %}", + data: { + csrfmiddlewaretoken: "{{ csrf_token }}", + //active: this.checked // true if checked else false + question_type: "rapid", + aid: el.dataset.aid, + status: 2, + }, + type: "POST", + dataType: "json", + }) + // $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly + .done(function (data) { + console.log(data); - if (data.success) { - toastr.info('Answer saved') - $(el).find(".confirm").remove() - $(el).removeClass("proposed-answer") - } - // show some message according to the response. - // For eg. A message box showing that the status has been changed - }) - .always(function () { - console.log('[Done]'); - }) - })) + if (data.success) { + toastr.info('Answer saved') + $(el).find(".confirm").remove() + $(el).removeClass("proposed-answer") + } + // show some message according to the response. + // For eg. A message box showing that the status has been changed + }) + .always(function () { + console.log('[Done]'); + }) + })) - // Add button to confirm answer is incorrect - $(el).append($("[Incorrect]").on("click", function () { - $.ajax({ - url: "{% url 'answer_suggestion_confirm' %}", - data: { - csrfmiddlewaretoken: "{{ csrf_token }}", - //active: this.checked // true if checked else false - question_type: "rapid", - aid: el.dataset.aid, - status: 0, - }, - type: "POST", - dataType: "json", - }) - // $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly - .done(function (data) { - console.log(data); + // Add button to confirm answer is incorrect + $(el).append($("[Incorrect]").on("click", function () { + $.ajax({ + url: "{% url 'answer_suggestion_confirm' %}", + data: { + csrfmiddlewaretoken: "{{ csrf_token }}", + //active: this.checked // true if checked else false + question_type: "rapid", + aid: el.dataset.aid, + status: 0, + }, + type: "POST", + dataType: "json", + }) + // $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly + .done(function (data) { + console.log(data); - if (data.success) { - toastr.info('Answer saved') - $(el).find(".confirm").remove() - $(el).removeClass("proposed-answer") - } - // show some message according to the response. - // For eg. A message box showing that the status has been changed - }) - .always(function () { - console.log('[Done]'); - }) - })) - }); + if (data.success) { + toastr.info('Answer saved') + $(el).find(".confirm").remove() + $(el).removeClass("proposed-answer") + } + // show some message according to the response. + // For eg. A message box showing that the status has been changed + }) + .always(function () { + console.log('[Done]'); + }) + })) + }); });