.
This commit is contained in:
@@ -72,29 +72,6 @@
|
||||
{% csrf_token %}
|
||||
|
||||
{% crispy form form.helper %}
|
||||
{% comment %} <h3>Cases:</h3>
|
||||
Add cases here. These can only be added once created (they can also be added to cases on creation). Click and drag to change order.
|
||||
<input type="button" value="Add More Cases" id="add_more_case">
|
||||
<input type=button id="case-order-button" title="click and drag to update case order" value="Update case order" />
|
||||
<div id="case_formset" class="sortable list_formset">
|
||||
<ol>
|
||||
{% for form in case_formset %}
|
||||
<li class="no-error case-formset">
|
||||
{{form.non_field_errors}}
|
||||
{{form.errors}}
|
||||
{{ form }}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ol>
|
||||
|
||||
</div>
|
||||
{{ case_formset.management_form }}
|
||||
</form>
|
||||
<div id="empty_case_form" style="display:none">
|
||||
<li class='no_error case-formset'>
|
||||
{{ case_formset.empty_form }}
|
||||
</li>
|
||||
</div> {% endcomment %}
|
||||
{% comment %} <input type="submit" class="submit-button" value="Submit" name="submit"> {% endcomment %}
|
||||
</form>
|
||||
<script>
|
||||
|
||||
+17
-10
@@ -1568,8 +1568,10 @@ class CaseCollectionCreate(RevisionMixin, LoginRequiredMixin, CreateView):
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(CaseCollectionCreate, self).get_context_data(**kwargs)
|
||||
|
||||
if self.request.POST:
|
||||
# Only bind the case formset when the POST actually contains formset data.
|
||||
# We don't require adding cases on create, so if the template doesn't
|
||||
# include the casedetail management fields we should skip validation.
|
||||
if self.request.POST and "casedetail_set-TOTAL_FORMS" in self.request.POST:
|
||||
context["case_formset"] = CaseCollectionCaseFormSet(
|
||||
self.request.POST,
|
||||
self.request.FILES,
|
||||
@@ -1589,14 +1591,19 @@ class CaseCollectionCreate(RevisionMixin, LoginRequiredMixin, CreateView):
|
||||
|
||||
context = self.get_context_data(form=form)
|
||||
case_formset = context["case_formset"]
|
||||
if case_formset.is_valid():
|
||||
response = super().form_valid(form)
|
||||
case_formset.instance = self.object
|
||||
case_formset.save()
|
||||
return response
|
||||
|
||||
else:
|
||||
return super().form_invalid(form)
|
||||
# If the POST included case formset data, validate and save it. Otherwise
|
||||
# skip formset processing so creating a collection without cases redirects
|
||||
# normally to the detail view.
|
||||
if self.request.POST and "casedetail_set-TOTAL_FORMS" in self.request.POST:
|
||||
if case_formset.is_valid():
|
||||
response = super().form_valid(form)
|
||||
case_formset.instance = self.object
|
||||
case_formset.save()
|
||||
return response
|
||||
else:
|
||||
return super().form_invalid(form)
|
||||
# No formset data present: proceed with normal create redirect.
|
||||
return super().form_valid(form)
|
||||
|
||||
def get_success_url(self):
|
||||
"""Redirect to the collection detail page after successful creation."""
|
||||
|
||||
Reference in New Issue
Block a user