fix some anatomy question creation bugs

This commit is contained in:
Ross
2024-10-14 10:08:54 +01:00
parent ffac3175e1
commit 8b84654ee3
7 changed files with 72 additions and 21 deletions
@@ -231,6 +231,8 @@
<p>This form can be used to create an Anatomy question.</p>
<p>Question type can be selected from a predefined list. If you require a more please contact ross.kruger@nhs.net.</p>
<p>Correct and incorrect answers can be defined once the question has been created.</p>
</details>
<form action="" method="post" enctype="multipart/form-data" id="anatomyquestion-form">
{% csrf_token %}
@@ -29,7 +29,10 @@
{% include 'anatomy/question_link_header.html' %}
{% endif %}
<h2>Question Answers</h2>
This page can be used to add and modify answers associated with a question. Answers in here will be used for automarking submitted answers so it is best not to remove. Updating an answer here will not automatically update a submitted answers (scores cache would need to be refreshed)
<details class="help-text">
<summary><i class="bi bi-info-circle"></i> Help</summary>
<p>This page can be used to add and modify answers associated with a question. Answers in here will be used for automarking submitted answers so it is best not to remove. Updating an answer here will not automatically update a submitted answers (scores cache would need to be refreshed)</p>
</details>
<form action="" method="post" enctype="multipart/form-data" id="anatomyquestion-form">
{% csrf_token %}
<h3>Answers:</h3>
@@ -45,7 +48,7 @@ This page can be used to add and modify answers associated with a question. Answ
{{ answer_formset.management_form }}
<input type="button" value="Add More Answers" id="add_more">
<p>
<input type="submit" class="submit-button" value="Submit" name="submit">
<input type="submit" class="submit-button btn btn-primary" value="Submit" name="submit">
</p>
</form>
<div id="empty_form" style="display:none">
+21 -14
View File
@@ -514,27 +514,34 @@ class AnatomyQuestionCreateBase(RevisionMixin, LoginRequiredMixin, CreateView):
self.object = form.save(commit=False)
self.object.save()
response = super().form_valid(form)
form.instance.author.add(self.request.user.id)
context = self.get_context_data(form=form)
formset = context["answer_formset"]
#context = self.get_context_data(form=form)
#formset = context["answer_formset"]
if formset.is_valid():
response = super().form_valid(form)
formset.instance = self.object
formset.save()
# If the normal submit button is pressed we save as normal
if "submit" in self.request.POST:
return response
# else we redirect to the clone url
else:
return redirect("anatomy:question_clone", pk=self.object.pk)
#if formset.is_valid():
# response = super().form_valid(form)
# formset.instance = self.object
# formset.save()
# # If the normal submit button is pressed we save as normal
# if "submit" in self.request.POST:
# return response
# # else we redirect to the clone url
# else:
# return redirect("anatomy:question_clone", pk=self.object.pk)
#else:
# return super().form_invalid(form)
# If the normal submit button is pressed we save as normal
if "submit" in self.request.POST:
return response
# else we redirect to the clone url
else:
return super().form_invalid(form)
return redirect("anatomy:question_clone", pk=self.object.pk)
def get_success_url(self) -> str:
return redirect("anatomy:question_detail", pk=self.object.pk)
return reverse("anatomy:question_detail", kwargs={"pk":self.object.pk})
class AnatomyQuestionCreate(AnatomyQuestionCreateBase):