From 74d3b3d3e9667b91b1b0dcdd271ae0d5ccdf2e55 Mon Sep 17 00:00:00 2001 From: "Casper V. Kristensen" Date: Sun, 27 Oct 2019 16:52:08 +0100 Subject: [PATCH] Update raid response formset with custom template, based on Crispy's default one, for better styling. --- drakul/raids/forms.py | 5 +- .../raid_response_table_inline_formset.html | 75 +++++++++++++++++++ 2 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 drakul/raids/templates/raids/raid_response_table_inline_formset.html diff --git a/drakul/raids/forms.py b/drakul/raids/forms.py index 7fc452a..e01e0f9 100644 --- a/drakul/raids/forms.py +++ b/drakul/raids/forms.py @@ -103,16 +103,16 @@ RaidResponseFormSet = inlineformset_factory( Raid, # parent model RaidResponse, fields=["character", "role", "status", "note", "attendance"], + can_delete=False, extra=1 ) class RaidResponseFormSetHelper(FormHelper): - template = "bootstrap4/table_inline_formset.html" + template = "raids/raid_response_table_inline_formset.html" def __init__(self, form=None): super().__init__(form) - self.form_class = "responses_form" self.layout = Layout( Field("character", css_class="character-select"), Field("role", css_class="role-select"), @@ -121,4 +121,3 @@ class RaidResponseFormSetHelper(FormHelper): Field("attendance", css_class="attendance-input"), ) self.form_tag = False - diff --git a/drakul/raids/templates/raids/raid_response_table_inline_formset.html b/drakul/raids/templates/raids/raid_response_table_inline_formset.html new file mode 100644 index 0000000..9cd90bd --- /dev/null +++ b/drakul/raids/templates/raids/raid_response_table_inline_formset.html @@ -0,0 +1,75 @@ +{% comment %} + Based on Crispy's default bootstrap4/table_inline_formset.html + https://github.com/django-crispy-forms/django-crispy-forms/blob/master/crispy_forms/templates/bootstrap4/table_inline_formset.html +{% endcomment %} + +{% load crispy_forms_tags %} +{% load crispy_forms_utils %} +{% load crispy_forms_field %} + +{% specialspaceless %} +{% if formset_tag %} +
+{% endif %} + {% if formset_method|lower == 'post' and not disable_csrf %} + {% csrf_token %} + {% endif %} + +
+ {{ formset.management_form|crispy }} +
+ + + + {% if formset.readonly and not formset.queryset.exists %} + {% else %} + + {% for field in formset.forms.0 %} + {% if field.label and not field.is_hidden %} + + {{ field.label|safe }}{% if field.field.required and not field|is_checkbox %}*{% endif %} + + {% endif %} + {% endfor %} + + {% endif %} + + + + + {% for field in formset.empty_form %} + {% include 'bootstrap4/field.html' with tag="td" form_show_labels=False %} + {% endfor %} + + + {% regroup formset by status.value as status_forms_list %} + {% for status, status_forms in status_forms_list %} + {% regroup status_forms by role.value as role_forms_list %} + {% for role, role_forms in role_forms_list %} + {% for form in role_forms %} + {% if form_show_errors and not form.is_extra %} + {% include "bootstrap4/errors.html" %} + {% endif %} + + {% for field in form %} + {% include 'bootstrap4/field.html' with tag="td" form_show_labels=False %} + {% endfor %} + + {% endfor %} + {% if not forloop.last %} + + {% endif %} + {% endfor %} + {% if not forloop.last %} + + + + {% endif %} + {% endfor %} + + + + {% include "bootstrap4/inputs.html" %} + +{% if formset_tag %}{% endif %} +{% endspecialspaceless %}