further improvements to questions

This commit is contained in:
Ross
2024-07-01 10:39:33 +01:00
parent b81fbbfea6
commit 00fa68247d
2 changed files with 145 additions and 15 deletions
+36
View File
@@ -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
@@ -121,23 +121,47 @@
</ul>
{% endif %}
<p>
<a href="{% url 'atlas:add_self_review' cid_user_exam.id case.id %}"><button>Add self review</button></a>
</p>
{% endif %}
<form method="POST" class="post-form">{% csrf_token %}
{% if collection.collection_type == "REP" or collection.collection_type == "QUE" %}
{{form.json.errors}}
<div class="form-contents">
<fieldset {% if question_completed %}disabled="disabled"{% endif %}>
{{form}}
</fieldset>
</div>
<p>
{% if question_completed %}
<form method="POST" class="post-form{% if question_completed %} completed{% endif %}">{% csrf_token %}
{% if collection.collection_type == "QUE" %}
{% if question_completed %}
<h3>Answers</h3>
<div class="answer-block">
{% for value, user_answer, correct_answer, answer_is_correct, automark in answer.get_correct_json_answers %}
<div class="{% if answer_is_correct %}
correct
{% else %}
incorrect
{% endif %}
{% if automark %}
automark
{% endif %}
">
<h4>{{value.title}}</h4>
{{value.description}}
<div
>
Answer : {{user_answer}}
{% if not answer_is_correct %}
<br/>Correct answer: {{correct_answer}}
{% endif %}
</div>
</div>
{% endfor %}
</div>
<div>
{% if collection.self_review %}
<p>
<a href="{% url 'atlas:add_self_review' cid_user_exam.id case.id %}"><button>Add self review</button></a>
</p>
{% if self_review %}
<h4>Self Feedback</h4>
@@ -151,9 +175,54 @@
Answer feedback: {{answer.feedback|safe}}
<br/>
{% endif %}
</div>
<details><summary>View questions</summary>
{{form.json.errors}}
<div class="form-contents">
<fieldset {% if question_completed %}disabled="disabled"{% endif %}>
{{form}}
</fieldset>
</div>
</details>
{% else %}
{{form.json.errors}}
<div class="form-contents">
<fieldset {% if question_completed %}disabled="disabled"{% endif %}>
{{form}}
</fieldset>
</div>
{% endif %}
{% elif collection.collection_type == "REP" %}
{{form.json.errors}}
<div class="form-contents">
<fieldset {% if question_completed %}disabled="disabled"{% endif %}>
{{form}}
</fieldset>
</div>
<div>
{% if collection.self_review %}
<p>
<a href="{% url 'atlas:add_self_review' cid_user_exam.id case.id %}"><button>Add self review</button></a>
</p>
{% if self_review %}
<h4>Self Feedback</h4>
{% for review in self_review %}
{{review.get_display_block}}
{% endfor %}
{% endif %}
{% else %}
<h4>Answer score: {{answer.score}}</h4>
Answer feedback: {{answer.feedback|safe}}
<br/>
{% endif %}
</p>
</div>
{% 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;
}
</style>
{% endblock %}
@@ -301,6 +395,6 @@ else {
});
})
{% endcomment %}
</script>
</script>
{% endblock js %}