1
0
mirror of https://github.com/django/django.git synced 2025-01-18 14:24:39 +00:00

Refs #32339 -- Removed transitional form renderers per deprecation timeline.

This commit is contained in:
Sarah Boyce 2024-12-12 16:37:17 +01:00
parent b5a6c93a18
commit ba90b76c6e
4 changed files with 4 additions and 81 deletions

View File

@ -1,11 +1,9 @@
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
@ -69,41 +67,6 @@ class Jinja2(EngineMixin, BaseRenderer):
return Jinja2
# RemovedInDjango60Warning.
class DjangoDivFormRenderer(DjangoTemplates):
"""
Load Django templates from django/forms/templates and from apps'
'templates' directory and use the 'div.html' template to render forms and
formsets.
"""
def __init__(self, *args, **kwargs):
warnings.warn(
"The DjangoDivFormRenderer transitional form renderer is deprecated. Use "
"DjangoTemplates instead.",
RemovedInDjango60Warning,
stacklevel=2,
)
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.
"""
def __init__(self, *args, **kwargs):
warnings.warn(
"The Jinja2DivFormRenderer transitional form renderer is deprecated. Use "
"Jinja2 instead.",
RemovedInDjango60Warning,
stacklevel=2,
)
super().__init__(*args, **kwargs)
class TemplatesSetting(BaseRenderer):
"""
Load templates using template.loader.get_template() which is configured

View File

@ -109,12 +109,6 @@ If you want to render templates with customizations from your
:setting:`TEMPLATES` setting, such as context processors for example, use the
:class:`TemplatesSetting` renderer.
.. class:: DjangoDivFormRenderer
.. deprecated:: 5.0
The alias of :class:`DjangoTemplates`.
``Jinja2``
----------
@ -131,12 +125,6 @@ templates for widgets that don't have any, you can't use this renderer. For
example, :mod:`django.contrib.admin` doesn't include Jinja2 templates for its
widgets due to their usage of Django template tags.
.. class:: Jinja2DivFormRenderer
.. deprecated:: 5.0
The alias of :class:`Jinja2`.
``TemplatesSetting``
--------------------

View File

@ -257,6 +257,9 @@ to remove usage of these features.
* Support for passing positional arguments to ``BaseConstraint`` is removed.
* The ``DjangoDivFormRenderer`` and ``Jinja2DivFormRenderer`` transitional form
renderers are removed.
See :ref:`deprecated-features-5.1` for details on these changes, including how
to remove usage of these features.

View File

@ -3,14 +3,11 @@ import unittest
from django.forms.renderers import (
BaseRenderer,
DjangoDivFormRenderer,
DjangoTemplates,
Jinja2,
Jinja2DivFormRenderer,
TemplatesSetting,
)
from django.test import SimpleTestCase, ignore_warnings
from django.utils.deprecation import RemovedInDjango60Warning
from django.test import SimpleTestCase
try:
import jinja2
@ -56,31 +53,3 @@ 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.assertWarnsMessage(RemovedInDjango60Warning, msg) as ctx:
DjangoDivFormRenderer()
self.assertEqual(ctx.filename, __file__)
def test_jinja2_div_renderer_warning(self):
msg = (
"The Jinja2DivFormRenderer transitional form renderer is deprecated. Use "
"Jinja2 instead."
)
with self.assertWarnsMessage(RemovedInDjango60Warning, msg) as ctx:
Jinja2DivFormRenderer()
self.assertEqual(ctx.filename, __file__)
@ignore_warnings(category=RemovedInDjango60Warning)
def test_deprecation_renderers_can_be_instantiated(self):
tests = [DjangoDivFormRenderer, Jinja2DivFormRenderer]
for cls in tests:
with self.subTest(renderer_class=cls):
renderer = cls()
self.assertIsInstance(renderer, cls)