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 warnings
|
||||
from pathlib import Path
|
||||
|
||||
from django.conf import settings
|
||||
from django.template.backends.django import DjangoTemplates
|
||||
from django.template.loader import get_template
|
||||
from django.utils.deprecation import RemovedInDjango60Warning
|
||||
from django.utils.functional import cached_property
|
||||
from django.utils.module_loading import import_string
|
||||
|
||||
|
@ -64,6 +66,7 @@ class Jinja2(EngineMixin, BaseRenderer):
|
|||
return Jinja2
|
||||
|
||||
|
||||
# RemovedInDjango60Warning.
|
||||
class DjangoDivFormRenderer(DjangoTemplates):
|
||||
"""
|
||||
Load Django templates from django/forms/templates and from apps'
|
||||
|
@ -71,22 +74,29 @@ class DjangoDivFormRenderer(DjangoTemplates):
|
|||
formsets.
|
||||
"""
|
||||
|
||||
# RemovedInDjango50Warning Deprecate this class in 5.0 and remove in 6.0.
|
||||
|
||||
form_template_name = "django/forms/div.html"
|
||||
formset_template_name = "django/forms/formsets/div.html"
|
||||
def __init__(self, *args, **kwargs):
|
||||
warnings.warn(
|
||||
"The DjangoDivFormRenderer transitional form renderer is deprecated. Use "
|
||||
"DjangoTemplates instead.",
|
||||
RemovedInDjango60Warning,
|
||||
)
|
||||
super.__init__(*args, **kwargs)
|
||||
|
||||
|
||||
# RemovedInDjango60Warning.
|
||||
class Jinja2DivFormRenderer(Jinja2):
|
||||
"""
|
||||
Load Jinja2 templates from the built-in widget templates in
|
||||
django/forms/jinja2 and from apps' 'jinja2' directory.
|
||||
"""
|
||||
|
||||
# RemovedInDjango50Warning Deprecate this class in 5.0 and remove in 6.0.
|
||||
|
||||
form_template_name = "django/forms/div.html"
|
||||
formset_template_name = "django/forms/formsets/div.html"
|
||||
def __init__(self, *args, **kwargs):
|
||||
warnings.warn(
|
||||
"The Jinja2DivFormRenderer transitional form renderer is deprecated. Use "
|
||||
"Jinja2 instead.",
|
||||
RemovedInDjango60Warning,
|
||||
)
|
||||
super.__init__(*args, **kwargs)
|
||||
|
||||
|
||||
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
|
||||
details on these changes.
|
||||
|
||||
* The ``DjangoDivFormRenderer`` and ``Jinja2DivFormRenderer`` transitional form
|
||||
renderers will be removed.
|
||||
|
||||
.. _deprecation-removed-in-5.1:
|
||||
|
||||
5.1
|
||||
|
|
|
@ -93,21 +93,9 @@ If you want to render templates with customizations from your
|
|||
|
||||
.. class:: DjangoDivFormRenderer
|
||||
|
||||
Subclass of :class:`DjangoTemplates` that specifies
|
||||
:attr:`~BaseRenderer.form_template_name` and
|
||||
:attr:`~BaseRenderer.formset_template_name` as ``"django/forms/div.html"`` and
|
||||
``"django/forms/formset/div.html"`` respectively.
|
||||
.. deprecated:: 5.0
|
||||
|
||||
This is a transitional renderer for opt-in to the new ``<div>`` based
|
||||
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.
|
||||
The alias of :class:`DjangoTemplates`.
|
||||
|
||||
``Jinja2``
|
||||
----------
|
||||
|
@ -127,12 +115,9 @@ widgets due to their usage of Django template tags.
|
|||
|
||||
.. class:: Jinja2DivFormRenderer
|
||||
|
||||
A transitional renderer as per :class:`DjangoDivFormRenderer` above, but
|
||||
subclassing :class:`Jinja2` for use with the Jinja2 backend.
|
||||
.. deprecated:: 5.0
|
||||
|
||||
Apply this via the :setting:`FORM_RENDERER` setting::
|
||||
|
||||
FORM_RENDERER = "django.forms.renderers.Jinja2DivFormRenderer"
|
||||
The alias of :class:`Jinja2`.
|
||||
|
||||
``TemplatesSetting``
|
||||
--------------------
|
||||
|
|
|
@ -233,9 +233,9 @@ Forms
|
|||
|
||||
* In order to smooth adoption of the new ``<div>`` output style, two
|
||||
transitional form renderer classes are available:
|
||||
:class:`django.forms.renderers.DjangoDivFormRenderer` and
|
||||
:class:`django.forms.renderers.Jinja2DivFormRenderer`, for the Django and
|
||||
Jinja2 template backends respectively.
|
||||
``django.forms.renderers.DjangoDivFormRenderer`` and
|
||||
``django.forms.renderers.Jinja2DivFormRenderer``, for the Django and Jinja2
|
||||
template backends respectively.
|
||||
|
||||
You can apply one of these via the :setting:`FORM_RENDERER` setting. For
|
||||
example::
|
||||
|
|
|
@ -247,7 +247,8 @@ Features deprecated in 5.0
|
|||
Miscellaneous
|
||||
-------------
|
||||
|
||||
* ...
|
||||
* The ``DjangoDivFormRenderer`` and ``Jinja2DivFormRenderer`` transitional form
|
||||
renderers are deprecated.
|
||||
|
||||
Features removed in 5.0
|
||||
=======================
|
||||
|
|
|
@ -3,11 +3,14 @@ import unittest
|
|||
|
||||
from django.forms.renderers import (
|
||||
BaseRenderer,
|
||||
DjangoDivFormRenderer,
|
||||
DjangoTemplates,
|
||||
Jinja2,
|
||||
Jinja2DivFormRenderer,
|
||||
TemplatesSetting,
|
||||
)
|
||||
from django.test import SimpleTestCase
|
||||
from django.utils.deprecation import RemovedInDjango60Warning
|
||||
|
||||
try:
|
||||
import jinja2
|
||||
|
@ -53,3 +56,21 @@ class Jinja2Tests(SharedTests, SimpleTestCase):
|
|||
|
||||
class TemplatesSettingTests(SharedTests, SimpleTestCase):
|
||||
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