Refs #15667 -- Removed support for Widget.render() methods without the renderer argument.

Per deprecation timeline.
This commit is contained in:
Tim Graham 2017-09-02 21:21:40 -04:00
parent ba42456c2e
commit 2bd207ada0
4 changed files with 4 additions and 53 deletions

View File

@ -1,12 +1,9 @@
import datetime
import warnings
from django.forms.utils import flatatt, pretty_name
from django.forms.widgets import Textarea, TextInput
from django.utils.deprecation import RemovedInDjango21Warning
from django.utils.functional import cached_property
from django.utils.html import conditional_escape, format_html, html_safe
from django.utils.inspect import func_accepts_kwargs, func_supports_parameter
from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy as _
@ -102,20 +99,11 @@ class BoundField:
else:
name = self.html_initial_name
kwargs = {}
if func_supports_parameter(widget.render, 'renderer') or func_accepts_kwargs(widget.render):
kwargs['renderer'] = self.form.renderer
else:
warnings.warn(
'Add the `renderer` argument to the render() method of %s. '
'It will be mandatory in Django 2.1.' % widget.__class__,
RemovedInDjango21Warning, stacklevel=2,
)
return widget.render(
name=name,
value=self.value(),
attrs=attrs,
**kwargs
renderer=self.form.renderer,
)
def as_text(self, attrs=None, **kwargs):

View File

@ -274,11 +274,6 @@ foundation for custom widgets.
``None``, the renderer from the :setting:`FORM_RENDERER` setting is
used.
.. versionchanged:: 1.11
The ``renderer`` argument was added. Support for subclasses that
don't accept it will be removed in Django 2.1.
.. method:: value_from_datadict(data, files, name)
Given a dictionary of data and this widget's name, returns the value

View File

@ -258,3 +258,6 @@ how to remove usage of these features.
* The ``Model._meta.has_auto_field`` attribute is removed.
* Support for regular expression groups with ``iLmsu#`` in ``url()`` is removed.
* Support for ``Widget.render()`` methods without the ``renderer`` argument
is removed.

View File

@ -1,35 +0,0 @@
from django import forms
from django.test import SimpleTestCase
from django.utils.deprecation import RemovedInDjango21Warning
class RenderDeprecationTests(SimpleTestCase):
def test_custom_widget_renderer_warning(self):
class CustomWidget1(forms.TextInput):
def render(self, name, value, attrs=None, renderer=None):
return super().render(name, value, attrs, renderer)
class CustomWidget2(forms.TextInput):
def render(self, *args, **kwargs):
return super().render(*args, **kwargs)
class CustomWidget3(forms.TextInput):
def render(self, name, value, attrs=None):
return super().render(name, value, attrs)
class MyForm(forms.Form):
foo = forms.CharField(widget=CustomWidget1)
bar = forms.CharField(widget=CustomWidget2)
baz = forms.CharField(widget=CustomWidget3)
form = MyForm()
str(form['foo']) # No warning.
str(form['bar']) # No warning.
msg = (
"Add the `renderer` argument to the render() method of <class "
"'forms_tests.widget_tests.test_render_deprecation"
".RenderDeprecationTests.test_custom_widget_renderer_warning.<locals>"
".CustomWidget3'>. It will be mandatory in Django 2.1."
)
with self.assertRaisesMessage(RemovedInDjango21Warning, msg):
str(form['baz'])