mirror of https://github.com/django/django.git
Refs #32339 -- Deprecated transitional form renderers.
This commit is contained in:
parent
3bbe22dafc
commit
b209518089
|
@ -1,9 +1,11 @@
|
||||||
import functools
|
import functools
|
||||||
|
import warnings
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.template.backends.django import DjangoTemplates
|
from django.template.backends.django import DjangoTemplates
|
||||||
from django.template.loader import get_template
|
from django.template.loader import get_template
|
||||||
|
from django.utils.deprecation import RemovedInDjango60Warning
|
||||||
from django.utils.functional import cached_property
|
from django.utils.functional import cached_property
|
||||||
from django.utils.module_loading import import_string
|
from django.utils.module_loading import import_string
|
||||||
|
|
||||||
|
@ -64,6 +66,7 @@ class Jinja2(EngineMixin, BaseRenderer):
|
||||||
return Jinja2
|
return Jinja2
|
||||||
|
|
||||||
|
|
||||||
|
# RemovedInDjango60Warning.
|
||||||
class DjangoDivFormRenderer(DjangoTemplates):
|
class DjangoDivFormRenderer(DjangoTemplates):
|
||||||
"""
|
"""
|
||||||
Load Django templates from django/forms/templates and from apps'
|
Load Django templates from django/forms/templates and from apps'
|
||||||
|
@ -71,22 +74,29 @@ class DjangoDivFormRenderer(DjangoTemplates):
|
||||||
formsets.
|
formsets.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# RemovedInDjango50Warning Deprecate this class in 5.0 and remove in 6.0.
|
def __init__(self, *args, **kwargs):
|
||||||
|
warnings.warn(
|
||||||
form_template_name = "django/forms/div.html"
|
"The DjangoDivFormRenderer transitional form renderer is deprecated. Use "
|
||||||
formset_template_name = "django/forms/formsets/div.html"
|
"DjangoTemplates instead.",
|
||||||
|
RemovedInDjango60Warning,
|
||||||
|
)
|
||||||
|
super.__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
# RemovedInDjango60Warning.
|
||||||
class Jinja2DivFormRenderer(Jinja2):
|
class Jinja2DivFormRenderer(Jinja2):
|
||||||
"""
|
"""
|
||||||
Load Jinja2 templates from the built-in widget templates in
|
Load Jinja2 templates from the built-in widget templates in
|
||||||
django/forms/jinja2 and from apps' 'jinja2' directory.
|
django/forms/jinja2 and from apps' 'jinja2' directory.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# RemovedInDjango50Warning Deprecate this class in 5.0 and remove in 6.0.
|
def __init__(self, *args, **kwargs):
|
||||||
|
warnings.warn(
|
||||||
form_template_name = "django/forms/div.html"
|
"The Jinja2DivFormRenderer transitional form renderer is deprecated. Use "
|
||||||
formset_template_name = "django/forms/formsets/div.html"
|
"Jinja2 instead.",
|
||||||
|
RemovedInDjango60Warning,
|
||||||
|
)
|
||||||
|
super.__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class TemplatesSetting(BaseRenderer):
|
class TemplatesSetting(BaseRenderer):
|
||||||
|
|
|
@ -15,6 +15,9 @@ about each item can often be found in the release notes of two versions prior.
|
||||||
See the :ref:`Django 5.0 release notes <deprecated-features-5.0>` for more
|
See the :ref:`Django 5.0 release notes <deprecated-features-5.0>` for more
|
||||||
details on these changes.
|
details on these changes.
|
||||||
|
|
||||||
|
* The ``DjangoDivFormRenderer`` and ``Jinja2DivFormRenderer`` transitional form
|
||||||
|
renderers will be removed.
|
||||||
|
|
||||||
.. _deprecation-removed-in-5.1:
|
.. _deprecation-removed-in-5.1:
|
||||||
|
|
||||||
5.1
|
5.1
|
||||||
|
|
|
@ -93,21 +93,9 @@ If you want to render templates with customizations from your
|
||||||
|
|
||||||
.. class:: DjangoDivFormRenderer
|
.. class:: DjangoDivFormRenderer
|
||||||
|
|
||||||
Subclass of :class:`DjangoTemplates` that specifies
|
.. deprecated:: 5.0
|
||||||
:attr:`~BaseRenderer.form_template_name` and
|
|
||||||
:attr:`~BaseRenderer.formset_template_name` as ``"django/forms/div.html"`` and
|
|
||||||
``"django/forms/formset/div.html"`` respectively.
|
|
||||||
|
|
||||||
This is a transitional renderer for opt-in to the new ``<div>`` based
|
The alias of :class:`DjangoTemplates`.
|
||||||
templates, which are the default from Django 5.0.
|
|
||||||
|
|
||||||
Apply this via the :setting:`FORM_RENDERER` setting::
|
|
||||||
|
|
||||||
FORM_RENDERER = "django.forms.renderers.DjangoDivFormRenderer"
|
|
||||||
|
|
||||||
Once the ``<div>`` templates are the default, this transitional renderer will
|
|
||||||
be deprecated, for removal in Django 6.0. The ``FORM_RENDERER`` declaration can
|
|
||||||
be removed at that time.
|
|
||||||
|
|
||||||
``Jinja2``
|
``Jinja2``
|
||||||
----------
|
----------
|
||||||
|
@ -127,12 +115,9 @@ widgets due to their usage of Django template tags.
|
||||||
|
|
||||||
.. class:: Jinja2DivFormRenderer
|
.. class:: Jinja2DivFormRenderer
|
||||||
|
|
||||||
A transitional renderer as per :class:`DjangoDivFormRenderer` above, but
|
.. deprecated:: 5.0
|
||||||
subclassing :class:`Jinja2` for use with the Jinja2 backend.
|
|
||||||
|
|
||||||
Apply this via the :setting:`FORM_RENDERER` setting::
|
The alias of :class:`Jinja2`.
|
||||||
|
|
||||||
FORM_RENDERER = "django.forms.renderers.Jinja2DivFormRenderer"
|
|
||||||
|
|
||||||
``TemplatesSetting``
|
``TemplatesSetting``
|
||||||
--------------------
|
--------------------
|
||||||
|
|
|
@ -233,9 +233,9 @@ Forms
|
||||||
|
|
||||||
* In order to smooth adoption of the new ``<div>`` output style, two
|
* In order to smooth adoption of the new ``<div>`` output style, two
|
||||||
transitional form renderer classes are available:
|
transitional form renderer classes are available:
|
||||||
:class:`django.forms.renderers.DjangoDivFormRenderer` and
|
``django.forms.renderers.DjangoDivFormRenderer`` and
|
||||||
:class:`django.forms.renderers.Jinja2DivFormRenderer`, for the Django and
|
``django.forms.renderers.Jinja2DivFormRenderer``, for the Django and Jinja2
|
||||||
Jinja2 template backends respectively.
|
template backends respectively.
|
||||||
|
|
||||||
You can apply one of these via the :setting:`FORM_RENDERER` setting. For
|
You can apply one of these via the :setting:`FORM_RENDERER` setting. For
|
||||||
example::
|
example::
|
||||||
|
|
|
@ -247,7 +247,8 @@ Features deprecated in 5.0
|
||||||
Miscellaneous
|
Miscellaneous
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
* ...
|
* The ``DjangoDivFormRenderer`` and ``Jinja2DivFormRenderer`` transitional form
|
||||||
|
renderers are deprecated.
|
||||||
|
|
||||||
Features removed in 5.0
|
Features removed in 5.0
|
||||||
=======================
|
=======================
|
||||||
|
|
|
@ -3,11 +3,14 @@ import unittest
|
||||||
|
|
||||||
from django.forms.renderers import (
|
from django.forms.renderers import (
|
||||||
BaseRenderer,
|
BaseRenderer,
|
||||||
|
DjangoDivFormRenderer,
|
||||||
DjangoTemplates,
|
DjangoTemplates,
|
||||||
Jinja2,
|
Jinja2,
|
||||||
|
Jinja2DivFormRenderer,
|
||||||
TemplatesSetting,
|
TemplatesSetting,
|
||||||
)
|
)
|
||||||
from django.test import SimpleTestCase
|
from django.test import SimpleTestCase
|
||||||
|
from django.utils.deprecation import RemovedInDjango60Warning
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import jinja2
|
import jinja2
|
||||||
|
@ -53,3 +56,21 @@ class Jinja2Tests(SharedTests, SimpleTestCase):
|
||||||
|
|
||||||
class TemplatesSettingTests(SharedTests, SimpleTestCase):
|
class TemplatesSettingTests(SharedTests, SimpleTestCase):
|
||||||
renderer = TemplatesSetting
|
renderer = TemplatesSetting
|
||||||
|
|
||||||
|
|
||||||
|
class DeprecationTests(SimpleTestCase):
|
||||||
|
def test_django_div_renderer_warning(self):
|
||||||
|
msg = (
|
||||||
|
"The DjangoDivFormRenderer transitional form renderer is deprecated. Use "
|
||||||
|
"DjangoTemplates instead."
|
||||||
|
)
|
||||||
|
with self.assertRaisesMessage(RemovedInDjango60Warning, msg):
|
||||||
|
DjangoDivFormRenderer()
|
||||||
|
|
||||||
|
def test_jinja2_div_renderer_warning(self):
|
||||||
|
msg = (
|
||||||
|
"The Jinja2DivFormRenderer transitional form renderer is deprecated. Use "
|
||||||
|
"Jinja2 instead."
|
||||||
|
)
|
||||||
|
with self.assertRaisesMessage(RemovedInDjango60Warning, msg):
|
||||||
|
Jinja2DivFormRenderer()
|
||||||
|
|
Loading…
Reference in New Issue