From 89e74e57b0a6e7c5a8460711cce92cdacab332af Mon Sep 17 00:00:00 2001 From: James Curtis Date: Sat, 10 Feb 2024 09:14:36 +0000 Subject: [PATCH 1/2] [IMP] Add formset template whole_uni_formset and errors_formset are required to be able to use formset_factory. Adds the required templates and enables the skipped tests with appropriate modifications to assertions. --- .../templates/bulma/errors_formset.html | 8 +++++ .../templates/bulma/layout/fieldset.html | 6 ++++ .../templates/bulma/whole_uni_formset.html | 30 +++++++++++++++++++ tests/test_layout.py | 11 ++----- 4 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 crispy_bulma/templates/bulma/errors_formset.html create mode 100644 crispy_bulma/templates/bulma/layout/fieldset.html create mode 100644 crispy_bulma/templates/bulma/whole_uni_formset.html diff --git a/crispy_bulma/templates/bulma/errors_formset.html b/crispy_bulma/templates/bulma/errors_formset.html new file mode 100644 index 0000000..0382973 --- /dev/null +++ b/crispy_bulma/templates/bulma/errors_formset.html @@ -0,0 +1,8 @@ +{% if formset.non_form_errors %} +
+ {% if formset_error_title %}

{{ formset_error_title }}

{% endif %} + +
+{% endif %} diff --git a/crispy_bulma/templates/bulma/layout/fieldset.html b/crispy_bulma/templates/bulma/layout/fieldset.html new file mode 100644 index 0000000..404e976 --- /dev/null +++ b/crispy_bulma/templates/bulma/layout/fieldset.html @@ -0,0 +1,6 @@ +
+ {% if legend %}{{ legend|safe }}{% endif %} + {{ fields|safe }} +
diff --git a/crispy_bulma/templates/bulma/whole_uni_formset.html b/crispy_bulma/templates/bulma/whole_uni_formset.html new file mode 100644 index 0000000..8bf199f --- /dev/null +++ b/crispy_bulma/templates/bulma/whole_uni_formset.html @@ -0,0 +1,30 @@ +{% load crispy_forms_tags %} +{% load crispy_forms_utils %} + +{% specialspaceless %} +{% if formset_tag %} +
+{% endif %} + {% if formset_method|lower == 'post' and not disable_csrf %} + {% csrf_token %} + {% endif %} + +
+ {{ formset.management_form|crispy }} +
+ + {% include "bulma/errors_formset.html" %} + + {% for form in formset %} + {% include "bulma/display_form.html" %} + {% endfor %} + + {% if inputs %} +
+ {% for input in inputs %} + {% include "bulma/layout/baseinput.html" %} + {% endfor %} +
+ {% endif %} +{% if formset_tag %}
{% endif %} +{% endspecialspaceless %} diff --git a/tests/test_layout.py b/tests/test_layout.py index 30e2900..0219b35 100644 --- a/tests/test_layout.py +++ b/tests/test_layout.py @@ -201,7 +201,6 @@ def test_layout_fieldset_row_html_with_unicode_fieldnames(): assert "testLink" in html -@pytest.mark.skip(reason="fieldset") def test_change_layout_dynamically_delete_field(): template = Template( """ @@ -240,7 +239,6 @@ def test_change_layout_dynamically_delete_field(): assert "email" not in html -@pytest.mark.skip(reason="fieldset") def test_column_has_css_classes(): template = Template( """ @@ -269,10 +267,9 @@ def test_column_has_css_classes(): html = template.render(c) assert html.count("formColumn") == 0 - assert html.count("col-md") == 1 + assert html.count("column") == 1 -@pytest.mark.skip(reason="formset") def test_formset_layout(): SampleFormSet = formset_factory(SampleForm, extra=3) formset = SampleFormSet() @@ -332,12 +329,11 @@ def test_formset_layout(): assert "Item 2" in html assert "Item 3" in html assert html.count("Note for first form only") == 1 - assert html.count("row") == 3 + assert html.count("columns") == 3 - assert html.count("mb-3") == 21 + assert html.count("control") == 18 -@pytest.mark.skip(reason="formset") def test_modelformset_layout(): CrispyModelFormSet = modelformset_factory( CrispyTestModel, form=SampleForm4, extra=3 @@ -375,7 +371,6 @@ def test_modelformset_layout(): assert html.count("password") == 0 -@pytest.mark.skip(reason="fieldset") def test_i18n(): template = Template( """ From 6340f8fc4d03c169b2d6072ebc8dfd18a83e660f Mon Sep 17 00:00:00 2001 From: James Curtis Date: Sat, 10 Feb 2024 09:32:19 +0000 Subject: [PATCH 2/2] [IMP] Add table_formset template --- .../templates/bulma/table_inline_formset.html | 57 +++++++++++++++++++ tests/test_layout.py | 4 +- 2 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 crispy_bulma/templates/bulma/table_inline_formset.html diff --git a/crispy_bulma/templates/bulma/table_inline_formset.html b/crispy_bulma/templates/bulma/table_inline_formset.html new file mode 100644 index 0000000..0a3478c --- /dev/null +++ b/crispy_bulma/templates/bulma/table_inline_formset.html @@ -0,0 +1,57 @@ +{% 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 }}{% if field.field.required and not field|is_checkbox %}*{% endif %} + + {% endif %} + {% endfor %} + + {% endif %} + + + + + {% for field in formset.empty_form %} + {% include 'bulma/field.html' with tag="td" form_show_labels=False %} + {% endfor %} + + + {% for form in formset %} + {% if form_show_errors and not form.is_extra %} + {% include "bulma/errors.html" %} + {% endif %} + + + {% for field in form %} + {% include 'bulma/field.html' with tag="td" form_show_labels=False %} + {% endfor %} + + {% endfor %} + + + + {% include "bulma/inputs.html" %} + +{% if formset_tag %}{% endif %} +{% endspecialspaceless %} diff --git a/tests/test_layout.py b/tests/test_layout.py index 0219b35..abcf2f5 100644 --- a/tests/test_layout.py +++ b/tests/test_layout.py @@ -512,7 +512,7 @@ def test_tabular_formset_layout(): SampleFormSet = formset_factory(SampleForm, extra=3) formset = SampleFormSet() formset.helper = FormHelper() - formset.helper.template = "bootstrap5/table_inline_formset.html" + formset.helper.template = "bulma/table_inline_formset.html" assert parse_form(formset) == parse_expected("test_tabular_formset_layout.html") SampleFormSet = formset_factory(SampleForm, extra=3) @@ -522,7 +522,7 @@ def test_tabular_formset_layout(): } formset = SampleFormSet(data) formset.helper = FormHelper() - formset.helper.template = "bootstrap5/table_inline_formset.html" + formset.helper.template = "bulma/table_inline_formset.html" assert parse_form(formset) == parse_expected( "test_tabular_formset_layout_failing.html" )