1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Refs #32339 -- Deprecated default.html form template.

Co-authored-by: Carlton Gibson <carlton.gibson@noumenal.es>
This commit is contained in:
David Smith
2022-05-05 14:26:09 +02:00
committed by Carlton Gibson
parent 6af8673255
commit d126eba363
12 changed files with 337 additions and 176 deletions

View File

@@ -15,6 +15,9 @@ def get_default_renderer():
class BaseRenderer:
# RemovedInDjango50Warning: When the deprecation ends, replace with
# form_template_name = "django/forms/div.html"
# formset_template_name = "django/forms/formsets/div.html"
form_template_name = "django/forms/default.html"
formset_template_name = "django/forms/formsets/default.html"
@@ -64,6 +67,31 @@ class Jinja2(EngineMixin, BaseRenderer):
return Jinja2
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.
"""
# 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"
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"
class TemplatesSetting(BaseRenderer):
"""
Load templates using template.loader.get_template() which is configured

View File

@@ -1,13 +1,16 @@
import json
import warnings
from collections import UserList
from django.conf import settings
from django.core.exceptions import ValidationError
from django.forms.renderers import get_default_renderer
from django.utils import timezone
from django.utils.deprecation import RemovedInDjango50Warning
from django.utils.html import escape, format_html_join
from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy as _
from django.utils.version import get_docs_version
def pretty_name(name):
@@ -42,6 +45,16 @@ def flatatt(attrs):
)
DEFAULT_TEMPLATE_DEPRECATION_MSG = (
'The "default.html" templates for forms and formsets will be removed. These were '
'proxies to the equivalent "table.html" templates, but the new "div.html" '
"templates will be the default from Django 5.0. Transitional renderers are "
"provided to allow you to opt-in to the new output style now. See "
"https://docs.djangoproject.com/en/%s/releases/4.1/ for more details"
% get_docs_version()
)
class RenderableMixin:
def get_context(self):
raise NotImplementedError(
@@ -49,12 +62,17 @@ class RenderableMixin:
)
def render(self, template_name=None, context=None, renderer=None):
return mark_safe(
(renderer or self.renderer).render(
template_name or self.template_name,
context or self.get_context(),
renderer = renderer or self.renderer
template = template_name or self.template_name
context = context or self.get_context()
if (
template == "django/forms/default.html"
or template == "django/forms/formsets/default.html"
):
warnings.warn(
DEFAULT_TEMPLATE_DEPRECATION_MSG, RemovedInDjango50Warning, stacklevel=2
)
)
return mark_safe(renderer.render(template, context))
__str__ = render
__html__ = render