Skip to content

Commit

Permalink
Passage au DSFR 1.13 (#192)
Browse files Browse the repository at this point in the history
* Remove support of Python < 3.10

* Deprecate tag {% dsfr_form %}

* Update Python dependencies
  • Loading branch information
Ash-Crow authored Jan 6, 2025
1 parent e7aa2d0 commit 222e7ec
Show file tree
Hide file tree
Showing 11 changed files with 286 additions and 473 deletions.
34 changes: 0 additions & 34 deletions .github/workflows/ci-3-8.yml

This file was deleted.

5 changes: 0 additions & 5 deletions .github/workflows/ci-3-10.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,10 @@ jobs:
- name: 🚧 Check pending migrations
run: |
poetry run python manage.py makemigrations --check --dry-run --noinput
- name: 🧪 Run Tests - Django 3
run: |
poetry run python manage.py test
- name: 🧪 Run Tests - Django 4
run: |
poetry add django@^4.1
poetry run python manage.py test
- name: 🧪 Run Tests - Django 5
run: |
sed -i 's/python = "^3.8"/python = "^3.10"/g' pyproject.toml
poetry add django@^5.0
poetry run python manage.py test
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

[![image](https://badge.fury.io/py/django-dsfr.svg)](https://pypi.org/project/django-dsfr/)

[![image](https://github.com/numerique-gouv/django-dsfr/actions/workflows/ci-3-8.yml/badge.svg)](https://github.com/numerique-gouv/django-dsfr/actions/workflows/ci-3-8.yml)

[![image](https://github.com/numerique-gouv/django-dsfr/actions/workflows/ci-3-10.yml/badge.svg)](https://github.com/numerique-gouv/django-dsfr/actions/workflows/ci-3-10.yml)
[![image](https://github.com/numerique-gouv/django-dsfr/actions/workflows/ci.yml/badge.svg)](https://github.com/numerique-gouv/django-dsfr/actions/workflows/ci.yml)

[![image](https://github.com/numerique-gouv/django-dsfr/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/numerique-gouv/django-dsfr/actions/workflows/codeql-analysis.yml)

Expand All @@ -23,14 +21,13 @@ Django-DSFR implements the [version 1.12.1 of the DSFR](https://www.systeme-de-d

## Requirements

Tested with Python 3.8 to 3.12 and Django 3.2 to 5.0. Per [vermin](https://github.com/netromdk/vermin), it should work with Python >= 3.6, and it should work with old versions of Django too.
Tested with Python 3.10 to 3.13 and the latest available version of Django 4 and 5.

Note: Only supported versions of Django and Python are supported by this project. You can check the supported versions and their end of life on the following pages:

- [Python](https://devguide.python.org/versions/)
- [Django](https://www.djangoproject.com/download/#supported-versions)

⚠️ Warning: Support for Django < 4.0 and Python < 3.10 will be removed at the end of 2024.

## Quick start

Expand Down
15 changes: 2 additions & 13 deletions config/settings.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
"""
Django settings for django-dsfr project.
Generated by 'django-admin startproject' using Django 3.2.5.
For more information on this file, see
https://docs.djangoproject.com/en/3.2/topics/settings/
https://docs.djangoproject.com/en/dev/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.2/ref/settings/
https://docs.djangoproject.com/en/dev/ref/settings/
"""

from pathlib import Path
import os
from django import VERSION as DJANGO_VERSION
import warnings

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
Expand All @@ -29,14 +26,6 @@

ALLOWED_HOSTS = []

warnings.simplefilter("default")
if DJANGO_VERSION < (4, 0):
warnings.warn(
"Support for Django < 4.0 will be deprecated in django-dsfr at the end of 2024.",
PendingDeprecationWarning,
stacklevel=3,
)

# Application definition

INSTALLED_APPS = [
Expand Down
5 changes: 2 additions & 3 deletions doc/forms.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,9 @@ def __init__(self, *args, **kwargs):
```

## Utilisation
Les formulaires sont appelés avec la balise `{{ form }}` (ou `{{ my_custom_form }}` le cas échéant).

La balise `{% dsfr_form %}` est maintenant dépréciée et sera retirée à la fin de l’année 2024.

Il faut donc remplacer les instances de `{% dsfr_form %}` par ``{{ form }}`` et `{% dsfr_form my_custom_form %}` par `{{ my_custom_form }}`.
La balise `{% dsfr_form %}` est maintenant dépréciée depuis Django-DSFR 2.0.0.

## Composants

Expand Down
44 changes: 9 additions & 35 deletions dsfr/templatetags/dsfr_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -1567,41 +1567,6 @@ def _render_alert_tag(message):
)


@register.inclusion_tag("dsfr/form_snippet.html", takes_context=True)
def dsfr_form(context: Context, form=None) -> dict:
"""
Returns the HTML for a form snippet.
<div role="alert" class="fr-alert fr-alert--warning">
<h3 class="fr-alert__title">This tag is obsolete and it will be removed at the end of 2024.</h3>
<p>
Please directly include the form with <code>{{ form }}</code> (or the name of the form context variable if different).
</p>
</div>
```python
data_dict = {
"form": an optional form to render instead of the form already present in context
}
```
**Tag name**:
dsfr_form
**Usage**:
`{% dsfr_form %}`
""" # noqa

warnings.warn(
"""The dsfr_form tag is deprecated and will be removed from django-dsfr at the end of 2024.
Please use a normal {{ form }} tag (requires Django 4 or superior)""",
DeprecationWarning,
stacklevel=2,
)

return context.update({"form": form}) if form else context # type: ignore


@register.inclusion_tag("dsfr/form_field_snippets/field_snippet.html")
def dsfr_form_field(field) -> dict:
"""
Expand Down Expand Up @@ -1713,3 +1678,12 @@ def dsfr_inline(field):
"""
field.field.widget.inline = True
return field


# Deprecated tags
@register.simple_tag(takes_context=True)
def dsfr_form(context: Context):
raise ValueError(
"""The dsfr_form tag is deprecated since django-dsfr 2.0.0.
Please use a normal {{ form }} tag.""",
)
41 changes: 0 additions & 41 deletions dsfr/test/test_templatetags.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import warnings

from django import forms
from django.test import SimpleTestCase
from django.template import Context, Template
from unittest.mock import MagicMock
Expand All @@ -14,7 +11,6 @@
INTEGRITY_JS_MODULE,
INTEGRITY_JS_NOMODULE,
)
from dsfr.forms import DsfrBaseForm
from dsfr.templatetags.dsfr_tags import concatenate, hyphenate


Expand Down Expand Up @@ -505,43 +501,6 @@ def test_consent_tag_rendered(self):
)


class DsfrFormTagTest(SimpleTestCase):
class TestForm(DsfrBaseForm):
test = forms.CharField(label="Ceci est un test")

class TestForm2(DsfrBaseForm):
test = forms.CharField(label="Ceci est un autre test")

context = Context({"form": TestForm(), "form2": TestForm2()})

def setUp(self) -> None:
warnings.simplefilter("ignore", category=DeprecationWarning, lineno=258)

def test_dsfr_form_renders(self):
rendered_template = Template("{% load dsfr_tags %} {% dsfr_form %}").render(
self.context
)
self.assertInHTML(
"""
<label for="id_test" class="fr-label">Ceci est un test*</label>
<input type="text" name="test" class="fr-input" required id="id_test">
""",
rendered_template,
)

def test_dsfr_form_renders_with_form_override(self):
rendered_template = Template(
"{% load dsfr_tags %} {% dsfr_form form2 %}"
).render(self.context)
self.assertInHTML(
"""
<label for="id_test" class="fr-label">Ceci est un autre test*</label>
<input type="text" name="test" class="fr-input" required id="id_test">
""",
rendered_template,
)


class DsfrContentTagTest(SimpleTestCase):
test_data = {
"alt_text": "Silhouette stylisée représentant le soleil au-dessus de deux montagnes.",
Expand Down
10 changes: 9 additions & 1 deletion example_app/dsfr_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,6 @@
},
"css": {"title": "CSS global"},
"js": {"title": "JS global"},
"form": {"title": "Formulaire"},
"form_field": {"title": "Formulaire - champ"},
"django_messages": {
"title": "Messages Django dans une alerte",
Expand Down Expand Up @@ -1186,10 +1185,19 @@
},
}

DEPRECATED_COMPONENTS = {
"form": {
"title": "Formulaire",
"since": "2.0.0",
"reason": "replaced with standard call to {{ form }}.",
},
}

all_tags_unsorted = {
**IMPLEMENTED_COMPONENTS,
**EXTRA_COMPONENTS,
**NOT_YET_IMPLEMENTED_COMPONENTS,
**WONT_BE_IMPLEMENTED,
**DEPRECATED_COMPONENTS,
}
ALL_TAGS = dict(sorted(all_tags_unsorted.items()))
1 change: 0 additions & 1 deletion example_app/templates/example_app/page_form.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{% extends "example_app/base.html" %}
{% load static dsfr_tags %}

{% block content %}
<h1>
Expand Down
Loading

0 comments on commit 222e7ec

Please sign in to comment.