Skip to content

Commit

Permalink
Add support for django 5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ckrybus committed Nov 30, 2023
1 parent 8a79154 commit ce8b94f
Show file tree
Hide file tree
Showing 15 changed files with 132 additions and 14 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ jobs:
strategy:
matrix:
python-version: [3.8, 3.9, "3.10", "3.11", "3.12"]
django: [4.2.*]
django: [4.2.*, 5.0.*]
crispy-forms: [2.0.*]
exclude:
- python-version: "3.12"
django: 4.2.*
- python-version: "3.8"
django: 5.0.*
- python-version: "3.9"
django: 5.0.*
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
Expand Down
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ History
Unreleased
----------

* Add support for Django 5.0
* Drop support for Django 3.2, 4.0 and 4.1


Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Requirements

Officially supported versions:

* Django: 4.2
* Django: 4.2, 5.0
* Python 3.8, 3.9, 3.10, 3.11, 3.12
* django-crispy-forms 2.0
* Bulma.css 0.9.4
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"Environment :: Web Environment",
"Framework :: Django",
"Framework :: Django :: 4.2",
"Framework :: Django :: 5.0",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
Expand Down
2 changes: 1 addition & 1 deletion tests/results/help_text_escape.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="field" id="div_id_email">
<label class="label" for="id_email">email<span class="asterisk">*</span></label>
<div class="control">
<input type="email" name="email" maxlength="320" class="input" id="id_email" required>
<input aria-describedby="id_email_helptext" type="email" name="email" maxlength="320" class="input" id="id_email" required>
</div>
<p class="help" id="hint_id_email">Insert your <b>email</b></p>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="field" id="div_id_email">
<label class="label" for="id_email">email<span class="asterisk">*</span></label>
<div class="control">
<input type="email" name="email" class="input" id="id_email" required>
<input type="email" name="email" maxlength="320" class="input" id="id_email" required>
</div>
<p class="help" id="hint_id_email">Insert your <b>email</b></p>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/results/test_email_field.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="field" id="div_id_email">
<label class="label" for="id_email">email<span class="asterisk">*</span></label>
<div class="control">
<input type="email" name="email" maxlength="30" class="input" id="id_email" required>
<input aria-describedby="id_email_helptext" type="email" name="email" maxlength="30" class="input" id="id_email" required>
</div>
<p class="help" id="hint_id_email">Insert your email</p>
</div>
Expand Down
9 changes: 9 additions & 0 deletions tests/results/test_email_field__lt50.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<form method="post">
<div class="field" id="div_id_email">
<label class="label" for="id_email">email<span class="asterisk">*</span></label>
<div class="control">
<input type="email" name="email" maxlength="30" class="input" id="id_email" required>
</div>
<p class="help" id="hint_id_email">Insert your email</p>
</div>
</form>
2 changes: 1 addition & 1 deletion tests/results/test_form_group.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</span>
</label>
<div class="control">
<input class="input" id="id_text_input" name="text_input" required type="text">
<input aria-describedby="id_text_input_helptext" class="input" id="id_text_input" name="text_input" required type="text">
</div>
<p class="help" id="hint_id_text_input">
help on a text_input
Expand Down
37 changes: 37 additions & 0 deletions tests/results/test_form_group__lt50.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<form method="post">
<div class="field" id="div_id_text_input">
<label class="label" for="id_text_input">
Text input<span class="asterisk">
*
</span>
</label>
<div class="control">
<input class="input" id="id_text_input" name="text_input" required type="text">
</div>
<p class="help" id="hint_id_text_input">
help on a text_input
</p>
</div>
<div class="field is-grouped">
<div class="control">
<div class="select">
<select id="id_fruit" name="fruit">
<option value="apple">
Apple
</option>
<option value="pear">
Pear
</option>
</select>
</div>
</div>
<div class="control">
<input class="button is-primary" id="submit-id-accept" name="accept" type="submit" value="Accept">
</div>
<div class="control">
<button class="button is-danger">
Reject
</button>
</div>
</div>
</form>
2 changes: 1 addition & 1 deletion tests/results/test_form_group_horizontal.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<div class="field-body">
<div class="field">
<div class="control">
<input class="input" id="id_text_input" name="text_input" required type="text">
<input aria-describedby="id_text_input_helptext" class="input" id="id_text_input" name="text_input" required type="text">
</div>
<p class="help" id="hint_id_text_input">
help on a text_input
Expand Down
48 changes: 48 additions & 0 deletions tests/results/test_form_group_horizontal__lt50.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<form method="post">
<div class="field is-horizontal" id="div_id_text_input">
<div class="field-label">
<label class="label" for="id_text_input">
Text input<span class="asterisk">
*
</span>
</label>
</div>
<div class="field-body">
<div class="field">
<div class="control">
<input class="input" id="id_text_input" name="text_input" required type="text">
</div>
<p class="help" id="hint_id_text_input">
help on a text_input
</p>
</div>
</div>
</div>
<div class="field is-horizontal">
<div class="field-label"></div>
<div class="field-body">
<div class="field is-grouped">
<div class="control">
<div class="select">
<select id="id_fruit" name="fruit">
<option value="apple">
Apple
</option>
<option value="pear">
Pear
</option>
</select>
</div>
</div>
<div class="control">
<input class="button is-primary" id="submit-id-accept" name="accept" type="submit" value="Accept">
</div>
<div class="control">
<button class="button is-danger">
Reject
</button>
</div>
</div>
</div>
</div>
</form>
20 changes: 15 additions & 5 deletions tests/test_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,10 +550,11 @@ def test_help_text_is_not_escaped():
form = HelpTextForm()
form.helper = FormHelper()

if django.VERSION >= (4, 0) and django.VERSION < (4, 1):
assert parse_form(form) == parse_expected("help_text_escape_legacy.html")
if django.VERSION < (5, 0):
result = "help_text_escape__lt50html"
else:
assert parse_form(form) == parse_expected("help_text_escape.html")
result = "help_text_escape.html"
assert parse_form(form) == parse_expected(result)


def test_form_group_form():
Expand All @@ -567,7 +568,16 @@ def test_form_group_form():
Button("Reject", css_class="is-danger"),
),
)
assert parse_form(form) == parse_expected("test_form_group.html")

if django.VERSION < (5, 0):
result = "test_form_group__lt50.html"
else:
result = "test_form_group.html"
assert parse_form(form) == parse_expected(result)

form.helper.form_horizontal = True
assert parse_form(form) == parse_expected("test_form_group_horizontal.html")
if django.VERSION < (5, 0):
result = "test_form_group_horizontal__lt50.html"
else:
result = "test_form_group_horizontal.html"
assert parse_form(form) == parse_expected(result)
8 changes: 7 additions & 1 deletion tests/test_layout_objects.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest

import django
from django import forms
from django.template import Context, Template
from django.utils.translation import activate, deactivate
Expand Down Expand Up @@ -28,7 +29,12 @@ def test_email_field():
form = SampleForm()
form.helper = FormHelper()
form.helper.layout = Layout("email")
assert parse_form(form) == parse_expected("test_email_field.html")

if django.VERSION < (5, 0):
result = "test_email_field__lt50.html"
else:
result = "test_email_field.html"
assert parse_form(form) == parse_expected(result)


def test_field_with_custom_template():
Expand Down
4 changes: 3 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
[tox]
envlist =
py{38,39,310}-django{42}-crispy{20},
py{311,312}-django{42,-latest}-crispy{20,-latest},
py{310}-django{50}-crispy{20,-latest},
py{311,312}-django{42,50,-latest}-crispy{20,-latest},

[testenv]
deps =
django42: django>=4.2a,<5.0
django50: django>=5.0a,<5.1
django-latest: https://github.com/django/django/archive/main.tar.gz
crispy20: django-crispy-forms>=2.0,<2.1
crispy-latest: https://github.com/django-crispy-forms/django-crispy-forms/archive/main.tar.gz
Expand Down

0 comments on commit ce8b94f

Please sign in to comment.