Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Django 5.0 support. #1367

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
144 changes: 144 additions & 0 deletions tests/results/test_formset_layout lt50.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<form action="/simple/action/" class="formsets-that-rock" id="thisFormsetRocks" method="post">
<input type="hidden" name="csrfmiddlewaretoken" value="aTestToken">
<div>
<input type="hidden" name="form-TOTAL_FORMS" value="3" id="id_form-TOTAL_FORMS">
<input type="hidden" name="form-INITIAL_FORMS" value="0" id="id_form-INITIAL_FORMS">
<input type="hidden" name="form-MIN_NUM_FORMS" value="0" id="id_form-MIN_NUM_FORMS">
<input type="hidden" name="form-MAX_NUM_FORMS" value="1000" id="id_form-MAX_NUM_FORMS">
</div>
<fieldset>
<legend>Item 1</legend>
<div class="form-group">
<div id="div_id_form-0-is_company" class="checkbox">
<label for="id_form-0-is_company" class="">
<input type="checkbox" name="form-0-is_company" class="checkboxinput" id="id_form-0-is_company">
company
</label>
</div>
</div>
<div id="div_id_form-0-email" class="form-group">
<label for="id_form-0-email" class="control-label requiredField"> email<span class="asteriskField">*</span></label>
<div class="controls ">
<input type="text" name="form-0-email" maxlength="30" class="textinput textInput inputtext form-control" id="id_form-0-email">
<div id="hint_id_form-0-email" class="help-block">Insert your email</div>
</div>
</div>
</fieldset>
Note for first form only
<div class="row ">
<div id="div_id_form-0-password1" class="form-group">
<label for="id_form-0-password1" class="control-label requiredField"> password<span class="asteriskField">*</span></label>
<div class="controls ">
<input type="password" name="form-0-password1" maxlength="30" class="passwordinput form-control" id="id_form-0-password1">
</div>
</div>
<div id="div_id_form-0-password2" class="form-group">
<label for="id_form-0-password2" class="control-label requiredField"> re-enter password<span class="asteriskField">*</span></label>
<div class="controls ">
<input type="password" name="form-0-password2" maxlength="30" class="passwordinput form-control" id="id_form-0-password2">
</div>
</div>
</div>
<fieldset>
<div id="div_id_form-0-first_name" class="form-group">
<label for="id_form-0-first_name" class="control-label requiredField"> first name<span class="asteriskField">*</span></label>
<div class="controls ">
<input type="text" name="form-0-first_name" maxlength="5" class="textinput textInput inputtext form-control" id="id_form-0-first_name">
</div>
</div>
<div id="div_id_form-0-last_name" class="form-group">
<label for="id_form-0-last_name" class="control-label requiredField"> last name<span class="asteriskField">*</span></label>
<div class="controls ">
<input type="text" name="form-0-last_name" maxlength="5" class="textinput textInput inputtext form-control" id="id_form-0-last_name">
</div>
</div>
</fieldset>
<fieldset>
<legend>Item 2</legend>
<div class="form-group">
<div id="div_id_form-1-is_company" class="checkbox">
<label for="id_form-1-is_company" class="">
<input type="checkbox" name="form-1-is_company" class="checkboxinput" id="id_form-1-is_company">
company
</label>
</div>
</div>
<div id="div_id_form-1-email" class="form-group">
<label for="id_form-1-email" class="control-label requiredField"> email<span class="asteriskField">*</span></label>
<div class="controls ">
<input type="text" name="form-1-email" maxlength="30" class="textinput textInput inputtext form-control" id="id_form-1-email">
<div id="hint_id_form-1-email" class="help-block">Insert your email</div>
</div>
</div>
</fieldset>
<div class="row ">
<div id="div_id_form-1-password1" class="form-group">
<label for="id_form-1-password1" class="control-label requiredField"> password<span class="asteriskField">*</span></label>
<div class="controls ">
<input type="password" name="form-1-password1" maxlength="30" class="passwordinput form-control" id="id_form-1-password1">
</div>
</div>
<div id="div_id_form-1-password2" class="form-group">
<label for="id_form-1-password2" class="control-label requiredField"> re-enter password<span class="asteriskField">*</span></label>
<div class="controls ">
<input type="password" name="form-1-password2" maxlength="30" class="passwordinput form-control" id="id_form-1-password2">
</div>
</div>
</div>
<fieldset>
<div id="div_id_form-1-first_name" class="form-group">
<label for="id_form-1-first_name" class="control-label requiredField"> first name<span class="asteriskField">*</span></label>
<div class="controls ">
<input type="text" name="form-1-first_name" maxlength="5" class="textinput textInput inputtext form-control" id="id_form-1-first_name">
</div>
</div>
<div id="div_id_form-1-last_name" class="form-group">
<label for="id_form-1-last_name" class="control-label requiredField"> last name<span class="asteriskField">*</span> </label>
<div class="controls ">
<input type="text" name="form-1-last_name" maxlength="5" class="textinput textInput inputtext form-control" id="id_form-1-last_name">
</div>
</div>
</fieldset>
<fieldset>
<legend>Item 3</legend>
<div class="form-group">
<div id="div_id_form-2-is_company" class="checkbox">
<label for="id_form-2-is_company" class="">
<input type="checkbox" name="form-2-is_company" class="checkboxinput" id="id_form-2-is_company">
company
</label>
</div>
</div>
<div id="div_id_form-2-email" class="form-group">
<label for="id_form-2-email" class="control-label requiredField"> email<span class="asteriskField">*</span> </label>
<div class="controls ">
<input type="text" name="form-2-email" maxlength="30" class="textinput textInput inputtext form-control" id="id_form-2-email">
<div id="hint_id_form-2-email" class="help-block">Insert your email</div>
</div>
</div>
</fieldset>
<div class="row ">
<div id="div_id_form-2-password1" class="form-group">
<label for="id_form-2-password1" class="control-label requiredField"> password<span class="asteriskField">*</span> </label>
<div class="controls ">
<input type="password" name="form-2-password1" maxlength="30" class="passwordinput form-control" id="id_form-2-password1"> </div>
</div>
<div id="div_id_form-2-password2" class="form-group">
<label for="id_form-2-password2" class="control-label requiredField"> re-enter password<span class="asteriskField">*</span> </label>
<div class="controls ">
<input type="password" name="form-2-password2" maxlength="30" class="passwordinput form-control" id="id_form-2-password2"> </div>
</div>
</div>
<fieldset>
<div id="div_id_form-2-first_name" class="form-group">
<label for="id_form-2-first_name" class="control-label requiredField"> first name<span class="asteriskField">*</span> </label>
<div class="controls ">
<input type="text" name="form-2-first_name" maxlength="5" class="textinput textInput inputtext form-control" id="id_form-2-first_name"> </div>
</div>
<div id="div_id_form-2-last_name" class="form-group">
<label for="id_form-2-last_name" class="control-label requiredField"> last name<span class="asteriskField">*</span> </label>
<div class="controls ">
<input type="text" name="form-2-last_name" maxlength="5" class="textinput textInput inputtext form-control" id="id_form-2-last_name"> </div>
</div>
</fieldset>
</form>
6 changes: 3 additions & 3 deletions tests/results/test_formset_layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<div id="div_id_form-0-email" class="form-group">
<label for="id_form-0-email" class="control-label requiredField"> email<span class="asteriskField">*</span></label>
<div class="controls ">
<input type="text" name="form-0-email" maxlength="30" class="textinput textInput inputtext form-control" id="id_form-0-email">
<input aria-describedby="id_form-0-email_helptext" type="text" name="form-0-email" maxlength="30" class="textinput textInput inputtext form-control" id="id_form-0-email">
<div id="hint_id_form-0-email" class="help-block">Insert your email</div>
</div>
</div>
Expand Down Expand Up @@ -66,7 +66,7 @@
<div id="div_id_form-1-email" class="form-group">
<label for="id_form-1-email" class="control-label requiredField"> email<span class="asteriskField">*</span></label>
<div class="controls ">
<input type="text" name="form-1-email" maxlength="30" class="textinput textInput inputtext form-control" id="id_form-1-email">
<input aria-describedby="id_form-1-email_helptext" type="text" name="form-1-email" maxlength="30" class="textinput textInput inputtext form-control" id="id_form-1-email">
<div id="hint_id_form-1-email" class="help-block">Insert your email</div>
</div>
</div>
Expand Down Expand Up @@ -112,7 +112,7 @@
<div id="div_id_form-2-email" class="form-group">
<label for="id_form-2-email" class="control-label requiredField"> email<span class="asteriskField">*</span> </label>
<div class="controls ">
<input type="text" name="form-2-email" maxlength="30" class="textinput textInput inputtext form-control" id="id_form-2-email">
<input aria-describedby="id_form-2-email_helptext" type="text" name="form-2-email" maxlength="30" class="textinput textInput inputtext form-control" id="id_form-2-email">
<div id="hint_id_form-2-email" class="help-block">Insert your email</div>
</div>
</div>
Expand Down
11 changes: 11 additions & 0 deletions tests/results/test_render_hidden_fields lt50.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<form method="post">
<div id="div_id_email" class="form-group">
<label for="id_email" class="control-label requiredField">email<span class="asteriskField">*</span></label>
<div class="controls ">
<input type="text" name="email" maxlength="30" class="textinput textInput inputtext form-control" required id="id_email">
<div id="hint_id_email" class="help-block">Insert your email</div>
</div>
</div>
<input type="hidden" name="password1" id="id_password1">
<input type="hidden" name="password2" id="id_password2">
</form>
2 changes: 1 addition & 1 deletion tests/results/test_render_hidden_fields.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div id="div_id_email" class="form-group">
<label for="id_email" class="control-label requiredField">email<span class="asteriskField">*</span></label>
<div class="controls ">
<input type="text" name="email" maxlength="30" class="textinput textInput inputtext form-control" required id="id_email">
<input aria-describedby="id_email_helptext" type="text" name="email" maxlength="30" class="textinput textInput inputtext form-control" required id="id_email">
<div id="hint_id_email" class="help-block">Insert your email</div>
</div>
</div>
Expand Down
6 changes: 5 additions & 1 deletion tests/test_form_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
7 changes: 6 additions & 1 deletion tests/test_layout.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import django
import pytest
from django import forms
from django.forms.models import formset_factory, modelformset_factory
Expand Down Expand Up @@ -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():
Expand Down
17 changes: 13 additions & 4 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import django
import pytest
from django import forms
from django.conf import settings
Expand Down Expand Up @@ -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 == [
{
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -184,14 +189,18 @@ 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",
"value": 1,
"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,
Expand All @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -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
Expand Down