fix some collection issues
This commit is contained in:
+15
-2
@@ -1028,6 +1028,12 @@ class SeriesDetail(models.Model):
|
||||
|
||||
|
||||
class CaseDetail(models.Model):
|
||||
"""A through table that stores the relationship between a case and a collection.
|
||||
|
||||
This is what user answers are linked to (as there be different questions for the same case in a different collection)
|
||||
|
||||
The collection questions and answers are also defined here.
|
||||
"""
|
||||
case = models.ForeignKey(Case, on_delete=models.CASCADE)
|
||||
collection = models.ForeignKey(CaseCollection, on_delete=models.CASCADE)
|
||||
|
||||
@@ -1109,8 +1115,15 @@ class BaseReportAnswer(models.Model):
|
||||
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]
|
||||
try:
|
||||
user_answer = self.json_answer[name]
|
||||
except KeyError: # If the schema has changed?
|
||||
user_answer = ""
|
||||
try:
|
||||
correct_answer = self.question.question_answers[name]
|
||||
except KeyError: # If the schema has changed?
|
||||
correct_answer = ""
|
||||
|
||||
print(correct_answer)
|
||||
|
||||
match value:
|
||||
|
||||
@@ -18,6 +18,15 @@
|
||||
|
||||
<h2>Case: <a href="{% url 'atlas:case_detail' case_detail.case.pk %}">{{case_detail.case.title}}</a></h2>
|
||||
|
||||
{% if case_detail.question_schema is not None and not case_detail.question_answers %}
|
||||
|
||||
|
||||
<div class="alert alert-danger" role="alert">
|
||||
<h4 class="alert-heading">Answers not defined!</h4>
|
||||
<p>A question schema has been defined but no question answers are found.</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<p>This form allows you to add questions to a case. A example of how the quesiton will be displayed is shown below.</p>
|
||||
<p>If answers are supplied the question will be automarked</p>
|
||||
|
||||
|
||||
@@ -44,6 +44,21 @@
|
||||
</button>
|
||||
<div id='case-list'></div>
|
||||
</p>
|
||||
|
||||
<details>
|
||||
<summary>Answer management</summary>
|
||||
|
||||
<div class="alert alert-danger">
|
||||
<p>Manage answers for this collection. </p>
|
||||
|
||||
Please note these are permanant and cannot be undone.
|
||||
</div>
|
||||
|
||||
<button title="This will clear all user answers and attempts"
|
||||
hx-post="{% url 'atlas:collection_reset_answers' collection.pk %}"
|
||||
>Reset all answers</button>
|
||||
|
||||
</summary>
|
||||
{% endif %}
|
||||
{% include 'exam_overview_js.html' %}
|
||||
{% endblock %}
|
||||
|
||||
@@ -131,6 +131,11 @@ urlpatterns = [
|
||||
views.collection_question_schemas,
|
||||
name="collection_question_schemas",
|
||||
),
|
||||
path(
|
||||
"collection/<int:exam_id>/reset_answers",
|
||||
views.collection_reset_answers,
|
||||
name="collection_reset_answers",
|
||||
),
|
||||
#path(
|
||||
# "question_schemas_preset",
|
||||
# views.question_schemas_preset,
|
||||
|
||||
@@ -2824,3 +2824,25 @@ def collection_question_schemas(request, exam_id: int):
|
||||
"case_details": case_details,
|
||||
},
|
||||
)
|
||||
|
||||
def collection_reset_answers(request, exam_id: int):
|
||||
if request.htmx:
|
||||
collection = get_object_or_404(CaseCollection, pk=exam_id)
|
||||
|
||||
# Select all case details (answers are linked to these)
|
||||
case_details = collection.casedetail_set.all().prefetch_related()
|
||||
|
||||
# Delete all answers
|
||||
cid_answers = case_details.cidreportanswer_set.all()
|
||||
user_answers = case_details.userreportanswer_set.all()
|
||||
|
||||
|
||||
# User statuses
|
||||
collection.exam_user_status.all().delete()
|
||||
|
||||
# CidUserExams
|
||||
CidUserExam.objects.filter(exam=collection).delete()
|
||||
|
||||
|
||||
else:
|
||||
raise Http404("Invalid request")
|
||||
Reference in New Issue
Block a user