fix some anatomy question creation bugs
This commit is contained in:
@@ -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">
|
||||
|
||||
+17
-10
@@ -514,15 +514,25 @@ 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 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
|
||||
@@ -530,11 +540,8 @@ class AnatomyQuestionCreateBase(RevisionMixin, LoginRequiredMixin, CreateView):
|
||||
else:
|
||||
return redirect("anatomy:question_clone", pk=self.object.pk)
|
||||
|
||||
else:
|
||||
return super().form_invalid(form)
|
||||
|
||||
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):
|
||||
|
||||
+1
-1
@@ -421,7 +421,7 @@ urlpatterns = [
|
||||
),
|
||||
path(
|
||||
"structure-autocomplete",
|
||||
views.StructureAutocomplete.as_view(model=Structure, create_field="name"),
|
||||
views.StructureAutocomplete.as_view(model=Structure, create_field="name", validate_create=True),
|
||||
name="structure-autocomplete",
|
||||
),
|
||||
path("presentation/", views.PresentationView.as_view(), name="presentation_view"),
|
||||
|
||||
+34
-4
@@ -66,7 +66,8 @@ import datetime
|
||||
from django.forms.utils import from_current_timezone, to_current_timezone
|
||||
|
||||
from crispy_forms.helper import FormHelper
|
||||
from crispy_forms.layout import Submit
|
||||
from crispy_forms.layout import Submit, Layout, Fieldset, Field, Div
|
||||
from crispy_forms.bootstrap import Accordion, AccordionGroup
|
||||
|
||||
from dal import autocomplete
|
||||
|
||||
@@ -119,7 +120,33 @@ class ExamFormMixin:
|
||||
self.helper.form_method = "post"
|
||||
self.helper.form_action = "submit"
|
||||
|
||||
self.helper.add_input(Submit("submit", "Submit"))
|
||||
self.helper.layout = Layout(
|
||||
Fieldset(
|
||||
"Exam Details",
|
||||
"name",
|
||||
"time_limit",
|
||||
"open_access",
|
||||
"authors_only",
|
||||
"exam_mode",
|
||||
"include_history",
|
||||
"active",
|
||||
"publish_results",
|
||||
"archive",
|
||||
Accordion(
|
||||
AccordionGroup("Date restrictions",
|
||||
"restrict_to_dates",
|
||||
"start_date",
|
||||
"end_date",
|
||||
)
|
||||
),
|
||||
),
|
||||
Div(
|
||||
Submit("submit", "Submit"),
|
||||
css_class="form-group",
|
||||
),
|
||||
)
|
||||
|
||||
# self.helper.add_input(Submit("submit", "Submit"))
|
||||
|
||||
# if user.is_superuser or user.groups.filter(name="cid_user_manager").exists():
|
||||
# cid_user_group_queryset = CidUserGroup.objects.filter(archive=False)
|
||||
@@ -675,6 +702,7 @@ class UserUserForm(Form):
|
||||
last_name = CharField(max_length=255, required=True)
|
||||
grade = ModelChoiceField(UserGrades.objects.all(), required=False)
|
||||
|
||||
|
||||
class TraineeForm(Form):
|
||||
username = EmailField(
|
||||
required=True,
|
||||
@@ -684,10 +712,12 @@ class TraineeForm(Form):
|
||||
last_name = CharField(max_length=255, required=True)
|
||||
grade = ModelChoiceField(UserGrades.objects.all(), required=False)
|
||||
supervisor = ModelChoiceField(
|
||||
Supervisor.objects.all().order_by("name"), required=False, widget=autocomplete.ModelSelect2(url='generic:supervisor-autocomplete')
|
||||
Supervisor.objects.all().order_by("name"),
|
||||
required=False,
|
||||
widget=autocomplete.ModelSelect2(url="generic:supervisor-autocomplete"),
|
||||
) # Needs to be a user/object ref
|
||||
|
||||
#class Meta:
|
||||
# class Meta:
|
||||
# widgets = {
|
||||
# "supervisor" : autocomplete.ModelSelect2(url='generic:supervisor-autocomplete')
|
||||
# }
|
||||
|
||||
@@ -30,3 +30,4 @@ if __name__ == "__main__":
|
||||
)
|
||||
raise
|
||||
execute_from_command_line(sys.argv)
|
||||
|
||||
|
||||
@@ -1313,3 +1313,11 @@ details.help-text > summary {
|
||||
#dicom-image .help-text:hover{
|
||||
background-color: rgba(0, 0, 0, 0.546);
|
||||
}
|
||||
|
||||
.accordion-item {
|
||||
background-color: black;
|
||||
}
|
||||
|
||||
.accordion-button {
|
||||
background-color: darkgray;
|
||||
}
|
||||
Reference in New Issue
Block a user