From 00fa68247d7541b8a51210edac53b294f49583e0 Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 1 Jul 2024 10:39:33 +0100 Subject: [PATCH] further improvements to questions --- atlas/models.py | 36 +++++ .../atlas/collection_case_view_take.html | 124 +++++++++++++++--- 2 files changed, 145 insertions(+), 15 deletions(-) diff --git a/atlas/models.py b/atlas/models.py index 333fd6a8..6cdde5fb 100644 --- a/atlas/models.py +++ b/atlas/models.py @@ -1005,6 +1005,10 @@ class CaseDetail(models.Model): def get_question_schema(self): return json.dumps(self.question_schema) + def get_question_answers(self): + """Returns the correct question answers as a json string""" + return json.dumps(self.question_answers) + class BaseReportAnswer(models.Model): question = models.ForeignKey(CaseDetail, on_delete=models.CASCADE) @@ -1043,6 +1047,38 @@ class BaseReportAnswer(models.Model): else: raise ValueError("No cid or user specified") + def get_correct_json_answers(self): + if self.question.question_schema is None or not "properties" in self.question.question_schema: + return [] + answers = [] + print("1", self.json_answer) + print("2", self.question.question_answers) + for name, value in self.question.question_schema["properties"].items(): + print(name, value) + + user_answer = self.json_answer[name] + correct_answer = self.question.question_answers[name] + print(correct_answer) + + match value: + case {"type": "string", "enum": _}: + print("YES", value) + automark = True + answer_is_correct = user_answer == correct_answer + case {"type": "string"}: + if user_answer == correct_answer: + automark = True + answer_is_correct = True + else: + automark = False + answer_is_correct = False + case _: + automark = False + answer_is_correct = user_answer == correct_answer + answers.append((value, user_answer, correct_answer, answer_is_correct, automark)) + + return answers + class Meta: abstract = True diff --git a/atlas/templates/atlas/collection_case_view_take.html b/atlas/templates/atlas/collection_case_view_take.html index 0a07608b..22b240d6 100644 --- a/atlas/templates/atlas/collection_case_view_take.html +++ b/atlas/templates/atlas/collection_case_view_take.html @@ -121,23 +121,47 @@ {% endif %} -

- -

{% endif %} -
{% csrf_token %} - {% if collection.collection_type == "REP" or collection.collection_type == "QUE" %} - {{form.json.errors}} -
-
- {{form}} -
-
-

- {% if question_completed %} + {% csrf_token %} + {% if collection.collection_type == "QUE" %} + {% if question_completed %} +

Answers

+
+ {% for value, user_answer, correct_answer, answer_is_correct, automark in answer.get_correct_json_answers %} +
+

{{value.title}}

+ {{value.description}} +
+ Answer : {{user_answer}} + + {% if not answer_is_correct %} +
Correct answer: {{correct_answer}} + {% endif %} + +
+
+ + {% endfor %} +
+ + +
{% if collection.self_review %} +

+ +

{% if self_review %}

Self Feedback

@@ -151,9 +175,54 @@ Answer feedback: {{answer.feedback|safe}}
{% endif %} +
+
View questions + {{form.json.errors}} +
+
+ {{form}} +
+
+
+ + {% else %} + + {{form.json.errors}} +
+
+ {{form}} +
+
+ + {% endif %} + + {% elif collection.collection_type == "REP" %} + {{form.json.errors}} +
+
+ {{form}} +
+
+
+ {% if collection.self_review %} +

+ +

+ {% if self_review %} +

Self Feedback

+ + {% for review in self_review %} + {{review.get_display_block}} + + {% endfor %} + {% endif %} + {% else %} +

Answer score: {{answer.score}}

+ Answer feedback: {{answer.feedback|safe}} +
{% endif %} -

+
{% endif %} {% if previous %} @@ -197,6 +266,31 @@ fieldset:disabled textarea { background-color: black; } + + form.completed { + } + + .correct { + } + + .correct h4::after { + content: '✓'; + color: green; + } + + .incorrect h4::after { + content: '✗'; + color: orange; + } + + .incorrect.automark h4::after { + content: '✗'; + color: red; + } + + .answer-block>div { + padding-top: 10px; + } {% endblock %} @@ -301,6 +395,6 @@ else { }); }) {% endcomment %} - + {% endblock js %}