From 47d238b69602711c06c369a5555bb554a4b3f7fb Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Sat, 20 Jan 2018 08:19:06 -0800 Subject: [PATCH] Fixed #29041 -- Changed SelectMultiple's multiple attribute to HTML5 boolean syntax. --- django/forms/widgets.py | 2 +- docs/ref/forms/widgets.txt | 2 +- docs/releases/2.1.txt | 4 ++++ tests/admin_widgets/tests.py | 4 ++-- .../field_tests/test_multivaluefield.py | 4 ++-- tests/forms_tests/tests/test_forms.py | 18 ++++++++--------- tests/forms_tests/tests/tests.py | 8 ++++---- .../widget_tests/test_multiwidget.py | 2 +- .../widget_tests/test_selectmultiple.py | 20 +++++++++---------- tests/model_forms/tests.py | 16 +++++++-------- 10 files changed, 42 insertions(+), 38 deletions(-) diff --git a/django/forms/widgets.py b/django/forms/widgets.py index 8ccf939acd..6ccbb86274 100644 --- a/django/forms/widgets.py +++ b/django/forms/widgets.py @@ -670,7 +670,7 @@ class Select(ChoiceWidget): def get_context(self, name, value, attrs): context = super().get_context(name, value, attrs) if self.allow_multiple_selected: - context['widget']['attrs']['multiple'] = 'multiple' + context['widget']['attrs']['multiple'] = True return context @staticmethod diff --git a/docs/ref/forms/widgets.txt b/docs/ref/forms/widgets.txt index 12677eb908..dc6256ee06 100644 --- a/docs/ref/forms/widgets.txt +++ b/docs/ref/forms/widgets.txt @@ -664,7 +664,7 @@ that specifies the template used to render each choice. For example, for the * ``option_template_name``: ``'django/forms/widgets/select_option.html'`` Similar to :class:`Select`, but allows multiple selection: - ```` + ```` ``RadioSelect`` ~~~~~~~~~~~~~~~ diff --git a/docs/releases/2.1.txt b/docs/releases/2.1.txt index b979ba2224..2c1f199577 100644 --- a/docs/releases/2.1.txt +++ b/docs/releases/2.1.txt @@ -251,6 +251,10 @@ Miscellaneous * ``allowed_hosts`` is now a required argument of private API ``django.utils.http.is_safe_url()``. +* The ``multiple`` attribute rendered by the + :class:`~django.forms.SelectMultiple` widget now uses HTML5 boolean syntax + rather than XHTML's ``mulitple="multiple"``. + .. _deprecated-features-2.1: Features deprecated in 2.1 diff --git a/tests/admin_widgets/tests.py b/tests/admin_widgets/tests.py index 0ce1c8e5d9..8c3f06670c 100644 --- a/tests/admin_widgets/tests.py +++ b/tests/admin_widgets/tests.py @@ -255,7 +255,7 @@ class FilteredSelectMultipleWidgetTest(SimpleTestCase): w = widgets.FilteredSelectMultiple('test\\', False) self.assertHTMLEqual( w.render('test', 'test'), - '' ) @@ -264,7 +264,7 @@ class FilteredSelectMultipleWidgetTest(SimpleTestCase): w = widgets.FilteredSelectMultiple('test\\', True) self.assertHTMLEqual( w.render('test', 'test'), - '' ) diff --git a/tests/forms_tests/field_tests/test_multivaluefield.py b/tests/forms_tests/field_tests/test_multivaluefield.py index cd446d07ce..edb32957e3 100644 --- a/tests/forms_tests/field_tests/test_multivaluefield.py +++ b/tests/forms_tests/field_tests/test_multivaluefield.py @@ -129,7 +129,7 @@ class MultiValueFieldTest(SimpleTestCase): """ - @@ -152,7 +152,7 @@ class MultiValueFieldTest(SimpleTestCase): """ - diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py index a6b157f044..4ec21f869e 100644 --- a/tests/forms_tests/tests/test_forms.py +++ b/tests/forms_tests/tests/test_forms.py @@ -760,7 +760,7 @@ Java composers = MultipleChoiceField() f = SongForm(auto_id=False) - self.assertHTMLEqual(str(f['composers']), """ """) class SongForm(Form): @@ -768,13 +768,13 @@ Java composers = MultipleChoiceField(choices=[('J', 'John Lennon'), ('P', 'Paul McCartney')]) f = SongForm(auto_id=False) - self.assertHTMLEqual(str(f['composers']), """ """) f = SongForm({'name': 'Yesterday', 'composers': ['P']}, auto_id=False) self.assertHTMLEqual(str(f['name']), '') - self.assertHTMLEqual(str(f['composers']), """ """) @@ -1865,7 +1865,7 @@ Password: """ p.as_ul(), """
  • Username:
  • Password:
  • -
  • Options: @@ -1881,7 +1881,7 @@ Username:
  • Password:
  • -Options: @@ -1895,7 +1895,7 @@ Options:
  • -Options: @@ -1909,7 +1909,7 @@ Options:
  • Password:
  • -
  • Options: @@ -1938,7 +1938,7 @@ Password:
  • p.as_ul(), """
  • Username:
  • Password:
  • -
  • Options: @@ -1949,7 +1949,7 @@ Password:
  • p.as_ul(), """
  • Username:
  • Password:
  • -
  • Options: diff --git a/tests/forms_tests/tests/tests.py b/tests/forms_tests/tests/tests.py index a54ad09c26..bf0d588f53 100644 --- a/tests/forms_tests/tests/tests.py +++ b/tests/forms_tests/tests/tests.py @@ -116,13 +116,13 @@ class ModelFormCallableModelDefault(TestCase):

    -

    - @@ -152,14 +152,14 @@ class ModelFormCallableModelDefault(TestCase):

    -

    - diff --git a/tests/forms_tests/widget_tests/test_multiwidget.py b/tests/forms_tests/widget_tests/test_multiwidget.py index f452ad2ad3..bce806231d 100644 --- a/tests/forms_tests/widget_tests/test_multiwidget.py +++ b/tests/forms_tests/widget_tests/test_multiwidget.py @@ -155,7 +155,7 @@ class MultiWidgetTest(WidgetTest): self.check_html(widget, 'name', 'some text,JP,2007-04-25 06:24:00', html=( """ - diff --git a/tests/forms_tests/widget_tests/test_selectmultiple.py b/tests/forms_tests/widget_tests/test_selectmultiple.py index 149fae6d4b..08606a18c4 100644 --- a/tests/forms_tests/widget_tests/test_selectmultiple.py +++ b/tests/forms_tests/widget_tests/test_selectmultiple.py @@ -15,7 +15,7 @@ class SelectMultipleTest(WidgetTest): def test_render_selected(self): self.check_html(self.widget(choices=self.beatles), 'beatles', ['J'], html=( - """ @@ -25,7 +25,7 @@ class SelectMultipleTest(WidgetTest): def test_render_multiple_selected(self): self.check_html(self.widget(choices=self.beatles), 'beatles', ['J', 'P'], html=( - """ @@ -38,7 +38,7 @@ class SelectMultipleTest(WidgetTest): If the value is None, none of the options are selected. """ self.check_html(self.widget(choices=self.beatles), 'beatles', None, html=( - """ @@ -52,7 +52,7 @@ class SelectMultipleTest(WidgetTest): of the options are selected. """ self.check_html(self.widget(choices=self.beatles), 'beatles', ['John'], html=( - """ @@ -65,7 +65,7 @@ class SelectMultipleTest(WidgetTest): Multiple options with the same value can be selected (#8103). """ self.check_html(self.widget(choices=self.numeric_choices), 'choices', ['0'], html=( - """ @@ -80,7 +80,7 @@ class SelectMultipleTest(WidgetTest): ones are selected. """ self.check_html(self.widget(choices=self.beatles), 'beatles', ['J', 'G', 'foo'], html=( - """ @@ -92,7 +92,7 @@ class SelectMultipleTest(WidgetTest): choices = [('1', '1'), ('2', '2'), ('3', '3')] self.check_html(self.widget(choices=choices), 'nums', [2], html=( - """ @@ -100,7 +100,7 @@ class SelectMultipleTest(WidgetTest): )) self.check_html(self.widget(choices=choices), 'nums', ['2'], html=( - """ @@ -108,7 +108,7 @@ class SelectMultipleTest(WidgetTest): )) self.check_html(self.widget(choices=choices), 'nums', [2], html=( - """ @@ -121,7 +121,7 @@ class SelectMultipleTest(WidgetTest): ('Group "1"', (('inner1', 'Inner 1'), ('inner2', 'Inner 2'))), )) self.check_html(widget, 'nestchoice', ['outer1', 'inner2'], html=( - """ diff --git a/tests/model_forms/tests.py b/tests/model_forms/tests.py index 7af2aff825..b6ce55cf40 100644 --- a/tests/model_forms/tests.py +++ b/tests/model_forms/tests.py @@ -1168,7 +1168,7 @@ class ModelFormBasicTests(TestCase):

  • Article:
  • -
  • Categories: @@ -1210,7 +1210,7 @@ class ModelFormBasicTests(TestCase):
  • Article:
  • -
  • Categories: @@ -1258,7 +1258,7 @@ class ModelFormBasicTests(TestCase): """
  • - @@ -1327,7 +1327,7 @@ class ModelFormBasicTests(TestCase): Article: -Categories: @@ -1357,7 +1357,7 @@ class ModelFormBasicTests(TestCase):
  • Article:
  • -
  • Categories: @@ -1501,7 +1501,7 @@ class ModelFormBasicTests(TestCase):
  • Article:
  • -
  • Categories: @@ -1527,7 +1527,7 @@ class ModelFormBasicTests(TestCase):
  • Article:
  • -
  • Categories: @@ -2681,7 +2681,7 @@ class OtherModelFormTests(TestCase): form.as_p(), """

    -

    """ % {'blue_pk': colour.pk})