From 4c5cea562d318887b45d6d11bd38c0540b68e3d2 Mon Sep 17 00:00:00 2001 From: David Smith <39445562+smithdc1@users.noreply.github.com> Date: Thu, 12 Oct 2023 13:10:21 +0100 Subject: [PATCH] Added Django 5.0 support. (#1367) --- CHANGELOG.md | 1 + pyproject.toml | 1 + tests/results/test_formset_layout lt50.html | 144 ++++++++++++++++++ tests/results/test_formset_layout.html | 6 +- .../test_render_hidden_fields lt50.html | 11 ++ tests/results/test_render_hidden_fields.html | 2 +- tests/test_form_helper.py | 6 +- tests/test_layout.py | 7 +- tests/test_utils.py | 17 ++- tox.ini | 4 +- 10 files changed, 188 insertions(+), 11 deletions(-) create mode 100644 tests/results/test_formset_layout lt50.html create mode 100644 tests/results/test_render_hidden_fields lt50.html diff --git a/CHANGELOG.md b/CHANGELOG.md index a9ed52ff..542cd568 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # CHANGELOG for django-crispy-forms ## Next Release (TBC) +* Added support for Django 5.0. * Add support for Python 3.12. * Dropped support for Python 3.7. diff --git a/pyproject.toml b/pyproject.toml index 6a9bf5e9..d7281eaf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,6 +14,7 @@ classifiers=[ "Framework :: Django :: 4.0", "Framework :: Django :: 4.1", "Framework :: Django :: 4.2", + "Framework :: Django :: 5.0", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: JavaScript", diff --git a/tests/results/test_formset_layout lt50.html b/tests/results/test_formset_layout lt50.html new file mode 100644 index 00000000..3846c1db --- /dev/null +++ b/tests/results/test_formset_layout lt50.html @@ -0,0 +1,144 @@ +
+ +
+ + + + +
+
+ Item 1 +
+
+ +
+
+
+ +
+ +
Insert your email
+
+
+
+ Note for first form only +
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ Item 2 +
+
+ +
+
+
+ +
+ +
Insert your email
+
+
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ Item 3 +
+
+ +
+
+
+ +
+ +
Insert your email
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
diff --git a/tests/results/test_formset_layout.html b/tests/results/test_formset_layout.html index 3846c1db..81927904 100644 --- a/tests/results/test_formset_layout.html +++ b/tests/results/test_formset_layout.html @@ -19,7 +19,7 @@
- +
Insert your email
@@ -66,7 +66,7 @@
- +
Insert your email
@@ -112,7 +112,7 @@
- +
Insert your email
diff --git a/tests/results/test_render_hidden_fields lt50.html b/tests/results/test_render_hidden_fields lt50.html new file mode 100644 index 00000000..8c9ce9fb --- /dev/null +++ b/tests/results/test_render_hidden_fields lt50.html @@ -0,0 +1,11 @@ +
+
+ +
+ +
Insert your email
+
+
+ + +
\ No newline at end of file diff --git a/tests/results/test_render_hidden_fields.html b/tests/results/test_render_hidden_fields.html index 8c9ce9fb..0f908c56 100644 --- a/tests/results/test_render_hidden_fields.html +++ b/tests/results/test_render_hidden_fields.html @@ -2,7 +2,7 @@
- +
Insert your email
diff --git a/tests/test_form_helper.py b/tests/test_form_helper.py index e45e1011..145d5be6 100644 --- a/tests/test_form_helper.py +++ b/tests/test_form_helper.py @@ -389,7 +389,11 @@ def test_render_hidden_fields(): # Now hide a couple of fields for field in ("password1", "password2"): test_form.fields[field].widget = forms.HiddenInput() - assert parse_expected("test_render_hidden_fields.html") == parse_form(test_form) + if django.VERSION < (5, 0): + result = "test_render_hidden_fields lt50.html" + else: + result = "test_render_hidden_fields.html" + assert parse_expected(result) == parse_form(test_form) def test_render_required_fields(): diff --git a/tests/test_layout.py b/tests/test_layout.py index e193d843..4ec5073d 100644 --- a/tests/test_layout.py +++ b/tests/test_layout.py @@ -1,3 +1,4 @@ +import django import pytest from django import forms from django.forms.models import formset_factory, modelformset_factory @@ -242,7 +243,11 @@ def test_formset_layout(): ) html = render_crispy_form(form=formset, helper=helper, context={"csrf_token": "aTestToken"}) - assert parse_expected("test_formset_layout.html") == parse_html(html) + if django.VERSION < (5, 0): + result = "test_formset_layout lt50.html" + else: + result = "test_formset_layout.html" + assert parse_expected(result) == parse_html(html) def test_modelformset_layout(): diff --git a/tests/test_utils.py b/tests/test_utils.py index 5b30b78b..17ce1fdf 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,3 +1,4 @@ +import django import pytest from django import forms from django.conf import settings @@ -143,6 +144,10 @@ def test_optgroup_filter(): groups = optgroups(form["checkbox_select_multiple"]) group = groups[0] label, option, index = group + if django.VERSION < (5, 0): + attrs = {"id": "id_checkbox_select_multiple_0", "checked": True} + else: + attrs = {"aria-invalid": "true", "checked": True, "id": "id_checkbox_select_multiple_0"} assert label is None assert option == [ { @@ -151,7 +156,7 @@ def test_optgroup_filter(): "label": 1, "selected": True, "index": "0", - "attrs": {"id": "id_checkbox_select_multiple_0", "checked": True}, + "attrs": attrs, "type": "checkbox", "template_name": "django/forms/widgets/checkbox_option.html", "wrap_label": True, @@ -171,7 +176,7 @@ def test_optgroup_filter(): "label": 1, "selected": True, "index": "0", - "attrs": {"id": "id_checkbox_select_multiple_0", "checked": True}, + "attrs": attrs, "type": "checkbox", "template_name": "django/forms/widgets/checkbox_option.html", "wrap_label": True, @@ -184,6 +189,10 @@ def test_optgroup_filter(): group = groups[0] label, option, index = group assert label is None + if django.VERSION < (5, 0): + attrs = {"id": "id_checkbox_select_multiple_0"} + else: + attrs = {"id": "id_checkbox_select_multiple_0", "aria-invalid": "true"} assert option == [ { "name": "checkbox_select_multiple", @@ -191,7 +200,7 @@ def test_optgroup_filter(): "label": 1, "selected": False, "index": "0", - "attrs": {"id": "id_checkbox_select_multiple_0"}, + "attrs": attrs, "type": "checkbox", "template_name": "django/forms/widgets/checkbox_option.html", "wrap_label": True, @@ -211,7 +220,7 @@ def test_optgroup_filter(): "label": 1, "selected": False, "index": "0", - "attrs": {"id": "id_checkbox_select_multiple_0"}, + "attrs": attrs, "type": "checkbox", "template_name": "django/forms/widgets/checkbox_option.html", "wrap_label": True, diff --git a/tox.ini b/tox.ini index a2a5d5d6..42c4385d 100644 --- a/tox.ini +++ b/tox.ini @@ -1,7 +1,8 @@ [tox] envlist = {py38,py39,py310}-django{32,40,41,42,-latest}, - {py311,py312}-django{41,42,-latest}, + {py310}-{django50} + {py311,py312}-django{41,42,50,-latest}, lint [testenv] @@ -10,6 +11,7 @@ deps = django40: django>=4.0a,<4.1 django41: django>=4.1a,<4.2 django42: django>=4.2a,<5.0 + django50: django>=5.0a,<5.1 django-latest: https://github.com/django/django/archive/main.tar.gz -rrequirements/testing.txt allowlist_externals = make