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 %} + <div class="alert alert-block alert-danger"> + {% if formset_error_title %}<h4 class="alert-heading">{{ formset_error_title }}</h4>{% endif %} + <ul class="m-0"> + {{ formset.non_form_errors|unordered_list }} + </ul> + </div> +{% 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 @@ +<fieldset {% if fieldset.css_id %}id="{{ fieldset.css_id }}"{% endif %} + {% if fieldset.css_class or form_style %}class="{{ fieldset.css_class }} {{ form_style }}"{% endif %} + {{ fieldset.flat_attrs }}> + {% if legend %}<legend>{{ legend|safe }}</legend>{% endif %} + {{ fields|safe }} +</fieldset> 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 %} +<form {{ flat_attrs }} method="{{ form_method }}" {% if formset.is_multipart %} enctype="multipart/form-data"{% endif %}> +{% endif %} + {% if formset_method|lower == 'post' and not disable_csrf %} + {% csrf_token %} + {% endif %} + + <div> + {{ formset.management_form|crispy }} + </div> + + <table{% if form_id %} id="{{ form_id }}_table"{% endif%} class="table table-striped table-sm"> + <thead> + {% if formset.readonly and not formset.queryset.exists %} + {% else %} + <tr> + {% for field in formset.forms.0 %} + {% if field.label and not field.is_hidden %} + <th for="{{ field.auto_id }}" class="{% if field.field.required %}requiredField{% endif %}"> + {{ field.label }}{% if field.field.required and not field|is_checkbox %}<span class="asteriskField">*</span>{% endif %} + </th> + {% endif %} + {% endfor %} + </tr> + {% endif %} + </thead> + + <tbody> + <tr class="d-none empty-form"> + {% for field in formset.empty_form %} + {% include 'bulma/field.html' with tag="td" form_show_labels=False %} + {% endfor %} + </tr> + + {% for form in formset %} + {% if form_show_errors and not form.is_extra %} + {% include "bulma/errors.html" %} + {% endif %} + + <tr> + {% for field in form %} + {% include 'bulma/field.html' with tag="td" form_show_labels=False %} + {% endfor %} + </tr> + {% endfor %} + </tbody> + </table> + + {% include "bulma/inputs.html" %} + +{% if formset_tag %}</form>{% endif %} +{% endspecialspaceless %} 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 %} +<form {{ flat_attrs }} method="{{ form_method }}" {% if formset.is_multipart %} enctype="multipart/form-data"{% endif %}> +{% endif %} + {% if formset_method|lower == 'post' and not disable_csrf %} + {% csrf_token %} + {% endif %} + + <div> + {{ formset.management_form|crispy }} + </div> + + {% include "bulma/errors_formset.html" %} + + {% for form in formset %} + {% include "bulma/display_form.html" %} + {% endfor %} + + {% if inputs %} + <div class="form-actions"> + {% for input in inputs %} + {% include "bulma/layout/baseinput.html" %} + {% endfor %} + </div> + {% endif %} +{% if formset_tag %}</form>{% endif %} +{% endspecialspaceless %} diff --git a/tests/test_layout.py b/tests/test_layout.py index 30e2900..abcf2f5 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( """ @@ -517,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) @@ -527,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" )