Skip to content

Commit

Permalink
[IMP] Add formset template
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
DaeronAlagos committed Feb 10, 2024
1 parent a7c228b commit 89e74e5
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 8 deletions.
8 changes: 8 additions & 0 deletions crispy_bulma/templates/bulma/errors_formset.html
Original file line number Diff line number Diff line change
@@ -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 %}
6 changes: 6 additions & 0 deletions crispy_bulma/templates/bulma/layout/fieldset.html
Original file line number Diff line number Diff line change
@@ -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>
30 changes: 30 additions & 0 deletions crispy_bulma/templates/bulma/whole_uni_formset.html
Original file line number Diff line number Diff line change
@@ -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 %}
11 changes: 3 additions & 8 deletions tests/test_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
"""
Expand Down Expand Up @@ -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(
"""
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -375,7 +371,6 @@ def test_modelformset_layout():
assert html.count("password") == 0


@pytest.mark.skip(reason="fieldset")
def test_i18n():
template = Template(
"""
Expand Down

0 comments on commit 89e74e5

Please sign in to comment.