diff --git a/django/contrib/admin/widgets.py b/django/contrib/admin/widgets.py index 0b66c7de1d..2103788de9 100644 --- a/django/contrib/admin/widgets.py +++ b/django/contrib/admin/widgets.py @@ -37,7 +37,7 @@ class FilteredSelectMultiple(forms.SelectMultiple): self.is_stacked = is_stacked super(FilteredSelectMultiple, self).__init__(attrs, choices) - def render(self, name, value, attrs=None, choices=()): + def render(self, name, value, attrs=None): if attrs is None: attrs = {} attrs['class'] = 'selectfilter' @@ -46,7 +46,7 @@ class FilteredSelectMultiple(forms.SelectMultiple): attrs['data-field-name'] = self.verbose_name attrs['data-is-stacked'] = int(self.is_stacked) - output = super(FilteredSelectMultiple, self).render(name, value, attrs, choices) + output = super(FilteredSelectMultiple, self).render(name, value, attrs) return mark_safe(output) diff --git a/django/forms/widgets.py b/django/forms/widgets.py index df585a6a2f..3d7f711056 100644 --- a/django/forms/widgets.py +++ b/django/forms/widgets.py @@ -514,12 +514,12 @@ class Select(Widget): memo[id(self)] = obj return obj - def render(self, name, value, attrs=None, choices=()): + def render(self, name, value, attrs=None): if value is None: value = '' final_attrs = self.build_attrs(attrs, name=name) output = [format_html('', flatatt(final_attrs))] - options = self.render_options(choices, [value]) + options = self.render_options([value]) if options: output.append(options) output.append('') @@ -541,11 +541,11 @@ class Select(Widget): selected_html, force_text(option_label)) - def render_options(self, choices, selected_choices): + def render_options(self, selected_choices): # Normalize to strings. selected_choices = set(force_text(v) for v in selected_choices) output = [] - for option_value, option_label in chain(self.choices, choices): + for option_value, option_label in self.choices: if isinstance(option_label, (list, tuple)): output.append(format_html('', force_text(option_value))) for option in option_label: @@ -566,12 +566,12 @@ class NullBooleanSelect(Select): ('3', ugettext_lazy('No'))) super(NullBooleanSelect, self).__init__(attrs, choices) - def render(self, name, value, attrs=None, choices=()): + def render(self, name, value, attrs=None): try: value = {True: '2', False: '3', '2': '2', '3': '3'}[value] except KeyError: value = '1' - return super(NullBooleanSelect, self).render(name, value, attrs, choices) + return super(NullBooleanSelect, self).render(name, value, attrs) def value_from_datadict(self, data, files, name): value = data.get(name) @@ -586,12 +586,12 @@ class NullBooleanSelect(Select): class SelectMultiple(Select): allow_multiple_selected = True - def render(self, name, value, attrs=None, choices=()): + def render(self, name, value, attrs=None): if value is None: value = [] final_attrs = self.build_attrs(attrs, name=name) output = [format_html('') @@ -625,7 +625,7 @@ class ChoiceInput(SubWidget): def __str__(self): return self.render() - def render(self, name=None, value=None, attrs=None, choices=()): + def render(self, name=None, value=None, attrs=None): if self.id_for_label: label_for = format_html(' for="{}"', self.id_for_label) else: diff --git a/docs/releases/1.10.txt b/docs/releases/1.10.txt index 7a3643969b..92f7c1d8e6 100644 --- a/docs/releases/1.10.txt +++ b/docs/releases/1.10.txt @@ -483,6 +483,11 @@ Miscellaneous * The default error views now raise ``TemplateDoesNotExist`` if a nonexistent ``template_name`` is specified. +* The unused ``choices`` keyword argument of the ``Select`` and + ``SelectMultiple`` widgets' ``render()`` method is removed. The ``choices`` + argument of the ``render_options()`` method is also removed, making + ``selected_choices`` the first argument. + .. _deprecated-features-1.10: Features deprecated in 1.10 diff --git a/tests/forms_tests/widget_tests/test_select.py b/tests/forms_tests/widget_tests/test_select.py index 86ef355c62..185352cda3 100644 --- a/tests/forms_tests/widget_tests/test_select.py +++ b/tests/forms_tests/widget_tests/test_select.py @@ -10,14 +10,14 @@ from .base import WidgetTest class SelectTest(WidgetTest): - widget = Select() + widget = Select nested_widget = Select(choices=( ('outer1', 'Outer 1'), ('Group "1"', (('inner1', 'Inner 1'), ('inner2', 'Inner 2'))), )) def test_render(self): - self.check_html(self.widget, 'beatle', 'J', choices=self.beatles, html=( + self.check_html(self.widget(choices=self.beatles), 'beatle', 'J', html=( """ @@ -44,7 +44,7 @@ class SelectTest(WidgetTest): If the value corresponds to a label (but not to an option value), none of the options are selected. """ - self.check_html(self.widget, 'beatle', 'John', choices=self.beatles, html=( + self.check_html(self.widget(choices=self.beatles), 'beatle', 'John', html=( """ @@ -90,8 +90,8 @@ class SelectTest(WidgetTest): The value is compared to its str(). """ self.check_html( - self.widget, 'num', 2, - choices=[('1', '1'), ('2', '2'), ('3', '3')], + self.widget(choices=[('1', '1'), ('2', '2'), ('3', '3')]), + 'num', 2, html=( """ @@ -112,8 +112,8 @@ class SelectTest(WidgetTest): ), ) self.check_html( - self.widget, 'num', 2, - choices=[(1, 1), (2, 2), (3, 3)], + self.widget(choices=[(1, 1), (2, 2), (3, 3)]), + 'num', 2, html=( """""" )) - def test_choices_constuctor_and_render(self): - """ - If 'choices' is passed to both the constructor and render(), then - they'll both be in the output. - """ - widget = Select(choices=[(1, 1), (2, 2), (3, 3)]) - self.check_html(widget, 'num', 2, choices=[(4, 4), (5, 5)], html=( - """""" - )) - def test_choices_escaping(self): choices = (('bad', 'you & me'), ('good', mark_safe('you > me'))) - self.check_html(self.widget, 'escape', None, choices=choices, html=( + self.check_html(self.widget(choices=choices), 'escape', None, html=( """ @@ -31,7 +31,7 @@ class SelectMultipleTest(WidgetTest): """ If the value is None, none of the options are selected. """ - self.check_html(self.widget, 'beatles', None, choices=self.beatles, html=( + self.check_html(self.widget(choices=self.beatles), 'beatles', None, html=( """ @@ -58,7 +58,7 @@ class SelectMultipleTest(WidgetTest): """ Multiple options with the same value can be selected (#8103). """ - self.check_html(self.widget, 'choices', ['0'], choices=self.numeric_choices, html=( + self.check_html(self.widget(choices=self.numeric_choices), 'choices', ['0'], html=( """ @@ -85,7 +85,7 @@ class SelectMultipleTest(WidgetTest): def test_compare_string(self): choices = [('1', '1'), ('2', '2'), ('3', '3')] - self.check_html(self.widget, 'nums', [2], choices=choices, html=( + self.check_html(self.widget(choices=choices), 'nums', [2], html=( """""" )) - self.check_html(self.widget, 'nums', ['2'], choices=choices, html=( + self.check_html(self.widget(choices=choices), 'nums', ['2'], html=( """""" )) - self.check_html(self.widget, 'nums', [2], choices=choices, html=( + self.check_html(self.widget(choices=choices), 'nums', [2], html=( """