From f213f4732c99757fdc0aa5e1528c9cb67d1c56c6 Mon Sep 17 00:00:00 2001 From: David Smith Date: Mon, 24 Feb 2025 13:21:31 +0000 Subject: [PATCH] Added Django 5.2. support. --- CHANGELOG.md | 1 + .../bootstrap4/layout/field_errors.html | 9 ++- .../bootstrap4/layout/field_errors_block.html | 9 ++- .../bootstrap_form_show_errors_bs4_false.html | 5 +- ...strap_form_show_errors_bs4_false_lt52.html | 72 +++++++++++++++++ .../bootstrap_form_show_errors_bs4_true.html | 17 ++-- ...tstrap_form_show_errors_bs4_true_lt50.html | 12 ++- ...tstrap_form_show_errors_bs4_true_lt52.html | 77 +++++++++++++++++++ ...rm_show_errors_non_field_errors_false.html | 6 +- ...ow_errors_non_field_errors_false_lt52.html | 40 ++++++++++ ...orm_show_errors_non_field_errors_true.html | 32 +++++--- ...how_errors_non_field_errors_true_lt50.html | 26 ++++--- ...how_errors_non_field_errors_true_lt52.html | 59 ++++++++++++++ ...ol_is_used_in_checkboxes_true_failing.html | 22 ++++-- ..._used_in_checkboxes_true_failing_lt50.html | 24 +++--- ...control_is_used_in_radio_true_failing.html | 8 +- ...ol_is_used_in_radio_true_failing_lt50.html | 8 +- .../test_grouped_checkboxes_failing.html | 8 +- .../test_grouped_checkboxes_failing_lt50.html | 8 +- .../test_grouped_radios_failing.html | 8 +- .../test_grouped_radios_failing_lt50.html | 8 +- tests/test_form_helper.py | 32 +++++--- tox.ini | 5 +- 23 files changed, 413 insertions(+), 83 deletions(-) create mode 100644 tests/results/bootstrap4/test_form_helper/bootstrap_form_show_errors_bs4_false_lt52.html create mode 100644 tests/results/bootstrap4/test_form_helper/bootstrap_form_show_errors_bs4_true_lt52.html create mode 100644 tests/results/bootstrap4/test_form_helper/test_form_show_errors_non_field_errors_false_lt52.html create mode 100644 tests/results/bootstrap4/test_form_helper/test_form_show_errors_non_field_errors_true_lt52.html diff --git a/CHANGELOG.md b/CHANGELOG.md index e024986..8533f5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Next Release * Added support for Python 3.13. +* Added support for Django 5.2. * Changed `id` for help text to align with aria-describedby attribute added by Django 5.0+. ## 2024.10 (2024-10-05) diff --git a/crispy_bootstrap4/templates/bootstrap4/layout/field_errors.html b/crispy_bootstrap4/templates/bootstrap4/layout/field_errors.html index f649872..b2d4dae 100644 --- a/crispy_bootstrap4/templates/bootstrap4/layout/field_errors.html +++ b/crispy_bootstrap4/templates/bootstrap4/layout/field_errors.html @@ -1,5 +1,12 @@ {% if form_show_errors and field.errors %} + {% if field.errors.field_id %} + {# Django 5.2+ #} +
+ {% else %} +
+ {% endif %} {% for error in field.errors %} - {{ error }} + {{ error }} {% endfor %} +
{% endif %} diff --git a/crispy_bootstrap4/templates/bootstrap4/layout/field_errors_block.html b/crispy_bootstrap4/templates/bootstrap4/layout/field_errors_block.html index e788b79..0c32aef 100644 --- a/crispy_bootstrap4/templates/bootstrap4/layout/field_errors_block.html +++ b/crispy_bootstrap4/templates/bootstrap4/layout/field_errors_block.html @@ -1,5 +1,12 @@ {% if form_show_errors and field.errors %} + {% if field.errors.field_id %} + {# Django 5.2+ #} +
+ {% else %} +
+ {% endif %} {% for error in field.errors %} -

{{ error }}

+

{{ error }}

{% endfor %} +
{% endif %} diff --git a/tests/results/bootstrap4/test_form_helper/bootstrap_form_show_errors_bs4_false.html b/tests/results/bootstrap4/test_form_helper/bootstrap_form_show_errors_bs4_false.html index 9bd16d5..3f6ec66 100644 --- a/tests/results/bootstrap4/test_form_helper/bootstrap_form_show_errors_bs4_false.html +++ b/tests/results/bootstrap4/test_form_helper/bootstrap_form_show_errors_bs4_false.html @@ -3,7 +3,7 @@
-
whatever
@@ -24,6 +24,7 @@ required id="id_first_name" aria-invalid="true" + aria-describedby="id_first_name_error" />
@@ -33,7 +34,7 @@
foo
-
bar
diff --git a/tests/results/bootstrap4/test_form_helper/bootstrap_form_show_errors_bs4_false_lt52.html b/tests/results/bootstrap4/test_form_helper/bootstrap_form_show_errors_bs4_false_lt52.html new file mode 100644 index 0000000..9bd16d5 --- /dev/null +++ b/tests/results/bootstrap4/test_form_helper/bootstrap_form_show_errors_bs4_false_lt52.html @@ -0,0 +1,72 @@ +
+
+ +
+
+ +
whatever
+
+ Insert your email +
+
+
+ +
+
+
blabla
+ +
+
+
+
+ +
+
+
foo
+ +
bar
+
+
+
+
+ +
+
+ +
whatever
+
+
+
+
+ +
+
+
blabla
+ +
+
+
+
diff --git a/tests/results/bootstrap4/test_form_helper/bootstrap_form_show_errors_bs4_true.html b/tests/results/bootstrap4/test_form_helper/bootstrap_form_show_errors_bs4_true.html index f976d4a..1c3da06 100644 --- a/tests/results/bootstrap4/test_form_helper/bootstrap_form_show_errors_bs4_true.html +++ b/tests/results/bootstrap4/test_form_helper/bootstrap_form_show_errors_bs4_true.html @@ -3,10 +3,12 @@
-
whatever
- Enter a valid email address. +
+ Enter a valid email address. +
Insert your email
@@ -21,9 +23,11 @@
blabla
- - Ensure this value has at most 5 characters (it has 19). +
+ Ensure this value has at most 5 characters (it has 19). +
@@ -41,9 +45,12 @@ required id="id_last_name" aria-invalid="true" + aria-describedby="id_last_name_error" />
bar
- Ensure this value has at most 5 characters (it has 18). +
+ Ensure this value has at most 5 characters (it has 18). +
diff --git a/tests/results/bootstrap4/test_form_helper/bootstrap_form_show_errors_bs4_true_lt50.html b/tests/results/bootstrap4/test_form_helper/bootstrap_form_show_errors_bs4_true_lt50.html index 95da460..7e3724f 100644 --- a/tests/results/bootstrap4/test_form_helper/bootstrap_form_show_errors_bs4_true_lt50.html +++ b/tests/results/bootstrap4/test_form_helper/bootstrap_form_show_errors_bs4_true_lt50.html @@ -5,7 +5,9 @@
whatever
- Enter a valid email address. +
+ Enter a valid email address. +
Insert your email @@ -21,7 +23,9 @@
blabla
- Ensure this value has at most 5 characters (it has 19). +
+ Ensure this value has at most 5 characters (it has 19). +
@@ -40,7 +44,9 @@ id="id_last_name" />
bar
- Ensure this value has at most 5 characters (it has 18). +
+ Ensure this value has at most 5 characters (it has 18). +
diff --git a/tests/results/bootstrap4/test_form_helper/bootstrap_form_show_errors_bs4_true_lt52.html b/tests/results/bootstrap4/test_form_helper/bootstrap_form_show_errors_bs4_true_lt52.html new file mode 100644 index 0000000..49e4d71 --- /dev/null +++ b/tests/results/bootstrap4/test_form_helper/bootstrap_form_show_errors_bs4_true_lt52.html @@ -0,0 +1,77 @@ +
+
+ +
+
+ +
whatever
+
+ Enter a valid email address. +
+
+ Insert your email +
+
+
+ +
+
+
blabla
+ +
+ Ensure this value has at most 5 characters (it has 19). +
+
+
+
+
+ +
+
+
foo
+ +
bar
+
+ Ensure this value has at most 5 characters (it has 18). +
+
+
+
+
+ +
+
+ +
whatever
+
+
+
+
+ +
+
+
blabla
+ +
+
+
+
\ No newline at end of file diff --git a/tests/results/bootstrap4/test_form_helper/test_form_show_errors_non_field_errors_false.html b/tests/results/bootstrap4/test_form_helper/test_form_show_errors_non_field_errors_false.html index ea6d23c..e32cab8 100644 --- a/tests/results/bootstrap4/test_form_helper/test_form_show_errors_non_field_errors_false.html +++ b/tests/results/bootstrap4/test_form_helper/test_form_show_errors_non_field_errors_false.html @@ -6,7 +6,7 @@
-
Insert your email
@@ -22,12 +22,12 @@
-
-
diff --git a/tests/results/bootstrap4/test_form_helper/test_form_show_errors_non_field_errors_false_lt52.html b/tests/results/bootstrap4/test_form_helper/test_form_show_errors_non_field_errors_false_lt52.html new file mode 100644 index 0000000..ea6d23c --- /dev/null +++ b/tests/results/bootstrap4/test_form_helper/test_form_show_errors_non_field_errors_false_lt52.html @@ -0,0 +1,40 @@ +
+
+
+
+
+
Insert your email
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
\ No newline at end of file diff --git a/tests/results/bootstrap4/test_form_helper/test_form_show_errors_non_field_errors_true.html b/tests/results/bootstrap4/test_form_helper/test_form_show_errors_non_field_errors_true.html index 0556212..6332b9e 100644 --- a/tests/results/bootstrap4/test_form_helper/test_form_show_errors_non_field_errors_true.html +++ b/tests/results/bootstrap4/test_form_helper/test_form_show_errors_non_field_errors_true.html @@ -11,10 +11,12 @@
-
This field is required. Insert your email
+
+
+ This field is required. +
+ Insert your email
@@ -28,24 +30,30 @@
-
This field is required. +
+
+ This field is required. +
-
This field is required. +
+
+ This field is required. +
This field is required. + class="timeinput form-control is-invalid" required id="id_datetime_field_1"> +
+ This field is required. +
\ No newline at end of file diff --git a/tests/results/bootstrap4/test_form_helper/test_form_show_errors_non_field_errors_true_lt50.html b/tests/results/bootstrap4/test_form_helper/test_form_show_errors_non_field_errors_true_lt50.html index 8063549..18ddc6d 100644 --- a/tests/results/bootstrap4/test_form_helper/test_form_show_errors_non_field_errors_true_lt50.html +++ b/tests/results/bootstrap4/test_form_helper/test_form_show_errors_non_field_errors_true_lt50.html @@ -12,9 +12,11 @@
This field is required. Insert your email
+ class="textinput textInput inputtext form-control is-invalid" required id="id_email"> +
+ This field is required. +
+ Insert your email
@@ -29,23 +31,29 @@
This field is required. + class="textinput textInput inputtext form-control is-invalid" required id="id_first_name"> +
+ This field is required. +
This field is required. + class="textinput textInput inputtext form-control is-invalid" required id="id_last_name"> +
+ This field is required. +
This field is required. + class="timeinput form-control is-invalid" required id="id_datetime_field_1"> +
+ This field is required. +
\ No newline at end of file diff --git a/tests/results/bootstrap4/test_form_helper/test_form_show_errors_non_field_errors_true_lt52.html b/tests/results/bootstrap4/test_form_helper/test_form_show_errors_non_field_errors_true_lt52.html new file mode 100644 index 0000000..f002fdb --- /dev/null +++ b/tests/results/bootstrap4/test_form_helper/test_form_show_errors_non_field_errors_true_lt52.html @@ -0,0 +1,59 @@ +
+
+
    +
  • Passwords dont match
  • +
+
+
+
+
+
+
+
+ This field is required. +
+ Insert your email
+
+
+
+
+
+
+
+
+
+
+ This field is required. +
+
+
+
+
+
+ This field is required. +
+
+
+
+ +
+
+ This field is required. +
+
+
+
\ No newline at end of file diff --git a/tests/results/bootstrap4/test_layout/test_use_custom_control_is_used_in_checkboxes_true_failing.html b/tests/results/bootstrap4/test_layout/test_use_custom_control_is_used_in_checkboxes_true_failing.html index 6def006..1877855 100644 --- a/tests/results/bootstrap4/test_layout/test_use_custom_control_is_used_in_checkboxes_true_failing.html +++ b/tests/results/bootstrap4/test_layout/test_use_custom_control_is_used_in_checkboxes_true_failing.html @@ -11,9 +11,11 @@
-

- This field is required. -

+
+

+ This field is required. +

+
@@ -34,9 +36,11 @@
-

+

+

This field is required. -

+

+
@@ -55,9 +59,11 @@ id="id_numeric_multiple_checkboxes_2" name="numeric_multiple_checkboxes" type="checkbox" value="3" aria-invalid="true"> -

- This field is required. -

+
+

+ This field is required. +

+
diff --git a/tests/results/bootstrap4/test_layout/test_use_custom_control_is_used_in_checkboxes_true_failing_lt50.html b/tests/results/bootstrap4/test_layout/test_use_custom_control_is_used_in_checkboxes_true_failing_lt50.html index f4ed162..3911244 100644 --- a/tests/results/bootstrap4/test_layout/test_use_custom_control_is_used_in_checkboxes_true_failing_lt50.html +++ b/tests/results/bootstrap4/test_layout/test_use_custom_control_is_used_in_checkboxes_true_failing_lt50.html @@ -11,9 +11,11 @@
-

- This field is required. -

+
+

+ This field is required. +

+
@@ -34,9 +36,11 @@
-

- This field is required. -

+
+

+ This field is required. +

+
@@ -55,9 +59,11 @@ id="id_numeric_multiple_checkboxes_2" name="numeric_multiple_checkboxes" type="checkbox" value="3"> -

- This field is required. -

+
+

+ This field is required. +

+
diff --git a/tests/results/bootstrap4/test_layout/test_use_custom_control_is_used_in_radio_true_failing.html b/tests/results/bootstrap4/test_layout/test_use_custom_control_is_used_in_radio_true_failing.html index f60d35e..ed1a519 100644 --- a/tests/results/bootstrap4/test_layout/test_use_custom_control_is_used_in_radio_true_failing.html +++ b/tests/results/bootstrap4/test_layout/test_use_custom_control_is_used_in_radio_true_failing.html @@ -11,9 +11,11 @@
-

- This field is required. -

+
+

+ This field is required. +

+
diff --git a/tests/results/bootstrap4/test_layout/test_use_custom_control_is_used_in_radio_true_failing_lt50.html b/tests/results/bootstrap4/test_layout/test_use_custom_control_is_used_in_radio_true_failing_lt50.html index deada1c..c1802c9 100644 --- a/tests/results/bootstrap4/test_layout/test_use_custom_control_is_used_in_radio_true_failing_lt50.html +++ b/tests/results/bootstrap4/test_layout/test_use_custom_control_is_used_in_radio_true_failing_lt50.html @@ -11,9 +11,11 @@
-

- This field is required. -

+
+

+ This field is required. +

+
diff --git a/tests/results/bootstrap4/test_layout_objects/test_grouped_checkboxes_failing.html b/tests/results/bootstrap4/test_layout_objects/test_grouped_checkboxes_failing.html index 93d241b..39fa48a 100644 --- a/tests/results/bootstrap4/test_layout_objects/test_grouped_checkboxes_failing.html +++ b/tests/results/bootstrap4/test_layout_objects/test_grouped_checkboxes_failing.html @@ -25,9 +25,11 @@ id="id_checkbox_select_multiple_2" name="checkbox_select_multiple" type="checkbox" value="unknown" aria-invalid="true"> -

- This field is required. -

+
+

+ This field is required. +

+
diff --git a/tests/results/bootstrap4/test_layout_objects/test_grouped_checkboxes_failing_lt50.html b/tests/results/bootstrap4/test_layout_objects/test_grouped_checkboxes_failing_lt50.html index 86cbb23..13df98a 100644 --- a/tests/results/bootstrap4/test_layout_objects/test_grouped_checkboxes_failing_lt50.html +++ b/tests/results/bootstrap4/test_layout_objects/test_grouped_checkboxes_failing_lt50.html @@ -25,9 +25,11 @@ id="id_checkbox_select_multiple_2" name="checkbox_select_multiple" type="checkbox" value="unknown"> -

- This field is required. -

+
+

+ This field is required. +

+
diff --git a/tests/results/bootstrap4/test_layout_objects/test_grouped_radios_failing.html b/tests/results/bootstrap4/test_layout_objects/test_grouped_radios_failing.html index 54f7022..1e2a17a 100644 --- a/tests/results/bootstrap4/test_layout_objects/test_grouped_radios_failing.html +++ b/tests/results/bootstrap4/test_layout_objects/test_grouped_radios_failing.html @@ -19,9 +19,11 @@
-

- This field is required. -

+
+

+ This field is required. +

+
diff --git a/tests/results/bootstrap4/test_layout_objects/test_grouped_radios_failing_lt50.html b/tests/results/bootstrap4/test_layout_objects/test_grouped_radios_failing_lt50.html index 2dd8460..313d17e 100644 --- a/tests/results/bootstrap4/test_layout_objects/test_grouped_radios_failing_lt50.html +++ b/tests/results/bootstrap4/test_layout_objects/test_grouped_radios_failing_lt50.html @@ -19,9 +19,11 @@
-

- This field is required. -

+
+

+ This field is required. +

+
diff --git a/tests/test_form_helper.py b/tests/test_form_helper.py index d73a0c4..05aef37 100644 --- a/tests/test_form_helper.py +++ b/tests/test_form_helper.py @@ -127,6 +127,11 @@ def test_form_show_errors_non_field_errors(settings): "bootstrap4/test_form_helper/" "test_form_show_errors_non_field_errors_true_lt50.html" ) + elif django.VERSION < (5, 2): + expected = parse_expected( + "bootstrap4/test_form_helper/" + "test_form_show_errors_non_field_errors_true_lt52.html" + ) else: expected = parse_expected( "bootstrap4/test_form_helper/" @@ -143,6 +148,11 @@ def test_form_show_errors_non_field_errors(settings): "bootstrap4/test_form_helper/" "test_form_show_errors_non_field_errors_false_lt50.html" ) + elif django.VERSION < (5, 2): + expected = parse_expected( + "bootstrap4/test_form_helper/" + "test_form_show_errors_non_field_errors_false_lt52.html" + ) else: expected = parse_expected( "bootstrap4/test_form_helper/" @@ -477,6 +487,10 @@ def test_bootstrap_form_show_errors_bs4(): expected = ( "bootstrap4/test_form_helper/bootstrap_form_show_errors_bs4_true_lt50.html" ) + elif django.VERSION < (5, 2): + expected = ( + "bootstrap4/test_form_helper/bootstrap_form_show_errors_bs4_true_lt52.html" + ) else: expected = ( "bootstrap4/test_form_helper/bootstrap_form_show_errors_bs4_true.html" @@ -487,6 +501,10 @@ def test_bootstrap_form_show_errors_bs4(): expected = ( "bootstrap4/test_form_helper/bootstrap_form_show_errors_bs4_false_lt50.html" ) + elif django.VERSION < (5, 2): + expected = ( + "bootstrap4/test_form_helper/bootstrap_form_show_errors_bs4_false_lt52.html" + ) else: expected = ( "bootstrap4/test_form_helper/bootstrap_form_show_errors_bs4_false.html" @@ -506,12 +524,7 @@ def test_error_text_inline(settings): form.is_valid() html = render_crispy_form(form) - help_class = "invalid-feedback" - help_tag_name = "div" - - matches = re.findall( - r'') - error_position = html.find('

') + help_position = html.find('') + error_position = html.find('

') assert help_position < error_position # Viceversa diff --git a/tox.ini b/tox.ini index b96ee64..b4574a4 100644 --- a/tox.ini +++ b/tox.ini @@ -4,8 +4,8 @@ max_line_length=118 [tox] envlist = {py38,py39,py310,py311}-django{42}-crispy{2,-latest}, - {py310,py311,py312}-django{50,51}-crispy{2,-latest}, - {py313}-django{51}-crispy{2,-latest}, + {py310,py311,py312}-django{50,51,52}-crispy{2,-latest}, + {py313}-django{51,52}-crispy{2,-latest}, lint [testenv] @@ -15,6 +15,7 @@ deps = django42: django>=4.2,<5.0 django50: django>=5.0,<5.1 django51: django>=5.1,<5.2 + django52: django>=5.2a1,<6.0 crispy2: django-crispy-forms>=2.3 crispy-latest: https://github.com/django-crispy-forms/django-crispy-forms/archive/main.tar.gz -rrequirements/testing.txt