1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

Fixed #27256 -- Changed Select widget's selected attribute to use HTML5 boolean syntax.

This commit is contained in:
Jon Dufresne 2016-09-21 15:12:13 -07:00 committed by GitHub
parent 42dc9d0400
commit 2c716c1dc7
18 changed files with 126 additions and 125 deletions

View File

@ -544,7 +544,7 @@ class Select(Widget):
option_value = ''
option_value = force_text(option_value)
if option_value in selected_choices:
selected_html = mark_safe(' selected="selected"')
selected_html = mark_safe(' selected')
if not self.allow_multiple_selected:
# Only allow for a single selection.
selected_choices.remove(option_value)

View File

@ -483,8 +483,9 @@ Miscellaneous
argument. Remove it because it doesn't have an effect in older versions of
Django as these fields alway strip whitespace.
* The ``checked`` attribute rendered by form widgets now uses HTML5 boolean
syntax rather than XHTML's ``checked='checked'``.
* The ``checked`` and ``selected`` attribute rendered by form widgets now uses
HTML5 boolean syntax rather than XHTML's ``checked='checked'`` and
``selected='selected'``.
* :meth:`RelatedManager.add()
<django.db.models.fields.related.RelatedManager.add>`,

View File

@ -771,7 +771,7 @@ with the ``Author`` model. It works just like a regular formset::
<input type="hidden" name="form-TOTAL_FORMS" value="1" id="id_form-TOTAL_FORMS" /><input type="hidden" name="form-INITIAL_FORMS" value="0" id="id_form-INITIAL_FORMS" /><input type="hidden" name="form-MAX_NUM_FORMS" id="id_form-MAX_NUM_FORMS" />
<tr><th><label for="id_form-0-name">Name:</label></th><td><input id="id_form-0-name" type="text" name="form-0-name" maxlength="100" /></td></tr>
<tr><th><label for="id_form-0-title">Title:</label></th><td><select name="form-0-title" id="id_form-0-title">
<option value="" selected="selected">---------</option>
<option value="" selected>---------</option>
<option value="MR">Mr.</option>
<option value="MRS">Mrs.</option>
<option value="MS">Ms.</option>

View File

@ -210,7 +210,7 @@ Include a form in ``template.html`` that will ``POST`` to this view:
<label for="timezone">Time zone:</label>
<select name="timezone">
{% for tz in timezones %}
<option value="{{ tz }}"{% if tz == TIME_ZONE %} selected="selected"{% endif %}>{{ tz }}</option>
<option value="{{ tz }}"{% if tz == TIME_ZONE %} selected{% endif %}>{{ tz }}</option>
{% endfor %}
</select>
<input type="submit" value="Set" />

View File

@ -1910,7 +1910,7 @@ Here's example HTML template code:
{% get_available_languages as LANGUAGES %}
{% get_language_info_list for LANGUAGES as languages %}
{% for language in languages %}
<option value="{{ language.code }}"{% if language.code == LANGUAGE_CODE %} selected="selected"{% endif %}>
<option value="{{ language.code }}"{% if language.code == LANGUAGE_CODE %} selected{% endif %}>
{{ language.name_local }} ({{ language.code }})
</option>
{% endfor %}

View File

@ -3335,7 +3335,7 @@ class AdminActionsTest(TestCase):
"""
response = self.client.get(reverse('admin:admin_views_externalsubscriber_changelist'))
self.assertContains(response, '''<label>Action: <select name="action" required>
<option value="" selected="selected">---------</option>
<option value="" selected>---------</option>
<option value="delete_selected">Delete selected external
subscribers</option>
<option value="redirect_to">Redirect to (Awesome action)</option>

View File

@ -137,8 +137,8 @@ class MultiValueFieldTest(SimpleTestCase):
<tr><th><label for="id_field1_0">Field1:</label></th>
<td><input type="text" name="field1_0" value="some text" id="id_field1_0" required />
<select multiple="multiple" name="field1_1" id="id_field1_1" required>
<option value="J" selected="selected">John</option>
<option value="P" selected="selected">Paul</option>
<option value="J" selected>John</option>
<option value="P" selected>Paul</option>
<option value="G">George</option>
<option value="R">Ringo</option>
</select>

View File

@ -508,19 +508,19 @@ class FormsTestCase(SimpleTestCase):
</select>""")
f = FrameworkForm({'name': 'Django', 'language': 'P'}, auto_id=False)
self.assertHTMLEqual(str(f['language']), """<select name="language" required>
<option value="P" selected="selected">Python</option>
<option value="P" selected>Python</option>
<option value="J">Java</option>
</select>""")
# A subtlety: If one of the choices' value is the empty string and the form is
# unbound, then the <option> for the empty-string choice will get selected="selected".
# unbound, then the <option> for the empty-string choice will get selected.
class FrameworkForm(Form):
name = CharField()
language = ChoiceField(choices=[('', '------'), ('P', 'Python'), ('J', 'Java')])
f = FrameworkForm(auto_id=False)
self.assertHTMLEqual(str(f['language']), """<select name="language" required>
<option value="" selected="selected">------</option>
<option value="" selected>------</option>
<option value="P">Python</option>
<option value="J">Java</option>
</select>""")
@ -537,7 +537,7 @@ class FormsTestCase(SimpleTestCase):
</select>""")
f = FrameworkForm({'name': 'Django', 'language': 'P'}, auto_id=False)
self.assertHTMLEqual(str(f['language']), """<select class="foo" name="language" required>
<option value="P" selected="selected">Python</option>
<option value="P" selected>Python</option>
<option value="J">Java</option>
</select>""")
@ -558,7 +558,7 @@ class FormsTestCase(SimpleTestCase):
</select>""")
f = FrameworkForm({'name': 'Django', 'language': 'P'}, auto_id=False)
self.assertHTMLEqual(str(f['language']), """<select class="foo" name="language" required>
<option value="P" selected="selected">Python</option>
<option value="P" selected>Python</option>
<option value="J">Java</option>
</select>""")
@ -724,7 +724,7 @@ Java</label></li>
self.assertHTMLEqual(str(f['name']), '<input type="text" name="name" value="Yesterday" required />')
self.assertHTMLEqual(str(f['composers']), """<select multiple="multiple" name="composers" required>
<option value="J">John Lennon</option>
<option value="P" selected="selected">Paul McCartney</option>
<option value="P" selected>Paul McCartney</option>
</select>""")
def test_form_with_disabled_fields(self):
@ -1814,8 +1814,8 @@ Password: <input type="password" name="password" required /></li>"""
"""<li>Username: <input type="text" name="username" value="django" maxlength="10" required /></li>
<li>Password: <input type="password" name="password" required /></li>
<li>Options: <select multiple="multiple" name="options" required>
<option value="f" selected="selected">foo</option>
<option value="b" selected="selected">bar</option>
<option value="f" selected>foo</option>
<option value="b" selected>bar</option>
<option value="w">whiz</option>
</select></li>"""
)
@ -1858,8 +1858,8 @@ Options: <select multiple="multiple" name="options" required>
<li><ul class="errorlist"><li>This field is required.</li></ul>
Password: <input type="password" name="password" required /></li>
<li>Options: <select multiple="multiple" name="options" required>
<option value="f" selected="selected">foo</option>
<option value="b" selected="selected">bar</option>
<option value="f" selected>foo</option>
<option value="b" selected>bar</option>
<option value="w">whiz</option>
</select></li>"""
)
@ -1888,8 +1888,8 @@ Password: <input type="password" name="password" required /></li>
<li>Password: <input type="password" name="password" required /></li>
<li>Options: <select multiple="multiple" name="options" required>
<option value="f">foo</option>
<option value="b" selected="selected">bar</option>
<option value="w" selected="selected">whiz</option>
<option value="b" selected>bar</option>
<option value="w" selected>whiz</option>
</select></li>"""
)
p = UserRegistration(initial={'username': initial_stephane, 'options': initial_options}, auto_id=False)
@ -1898,8 +1898,8 @@ Password: <input type="password" name="password" required /></li>
"""<li>Username: <input type="text" name="username" value="stephane" maxlength="10" required /></li>
<li>Password: <input type="password" name="password" required /></li>
<li>Options: <select multiple="multiple" name="options" required>
<option value="f" selected="selected">foo</option>
<option value="b" selected="selected">bar</option>
<option value="f" selected>foo</option>
<option value="b" selected>bar</option>
<option value="w">whiz</option>
</select></li>"""
)
@ -2319,39 +2319,39 @@ Password: <input type="password" name="password" required />
p = Person({'name': 'Joe'}, auto_id=False)
self.assertHTMLEqual(str(p['is_cool']), """<select name="is_cool" required>
<option value="1" selected="selected">Unknown</option>
<option value="1" selected>Unknown</option>
<option value="2">Yes</option>
<option value="3">No</option>
</select>""")
p = Person({'name': 'Joe', 'is_cool': '1'}, auto_id=False)
self.assertHTMLEqual(str(p['is_cool']), """<select name="is_cool" required>
<option value="1" selected="selected">Unknown</option>
<option value="1" selected>Unknown</option>
<option value="2">Yes</option>
<option value="3">No</option>
</select>""")
p = Person({'name': 'Joe', 'is_cool': '2'}, auto_id=False)
self.assertHTMLEqual(str(p['is_cool']), """<select name="is_cool" required>
<option value="1">Unknown</option>
<option value="2" selected="selected">Yes</option>
<option value="2" selected>Yes</option>
<option value="3">No</option>
</select>""")
p = Person({'name': 'Joe', 'is_cool': '3'}, auto_id=False)
self.assertHTMLEqual(str(p['is_cool']), """<select name="is_cool" required>
<option value="1">Unknown</option>
<option value="2">Yes</option>
<option value="3" selected="selected">No</option>
<option value="3" selected>No</option>
</select>""")
p = Person({'name': 'Joe', 'is_cool': True}, auto_id=False)
self.assertHTMLEqual(str(p['is_cool']), """<select name="is_cool" required>
<option value="1">Unknown</option>
<option value="2" selected="selected">Yes</option>
<option value="2" selected>Yes</option>
<option value="3">No</option>
</select>""")
p = Person({'name': 'Joe', 'is_cool': False}, auto_id=False)
self.assertHTMLEqual(str(p['is_cool']), """<select name="is_cool" required>
<option value="1">Unknown</option>
<option value="2">Yes</option>
<option value="3" selected="selected">No</option>
<option value="3" selected>No</option>
</select>""")
def test_forms_with_file_fields(self):
@ -2715,7 +2715,7 @@ Good luck picking a username that doesn&#39;t already exist.</p>
<label class="required" for="id_name">Name:</label> <input type="text" name="name" id="id_name" required /></li>
<li class="required"><label class="required" for="id_is_cool">Is cool:</label>
<select name="is_cool" id="id_is_cool" required>
<option value="1" selected="selected">Unknown</option>
<option value="1" selected>Unknown</option>
<option value="2">Yes</option>
<option value="3">No</option>
</select></li>
@ -2731,7 +2731,7 @@ Good luck picking a username that doesn&#39;t already exist.</p>
<input type="text" name="name" id="id_name" required /></p>
<p class="required"><label class="required" for="id_is_cool">Is cool:</label>
<select name="is_cool" id="id_is_cool" required>
<option value="1" selected="selected">Unknown</option>
<option value="1" selected>Unknown</option>
<option value="2">Yes</option>
<option value="3">No</option>
</select></p>
@ -2749,7 +2749,7 @@ Good luck picking a username that doesn&#39;t already exist.</p>
<input type="text" name="name" id="id_name" required /></td></tr>
<tr class="required"><th><label class="required" for="id_is_cool">Is cool:</label></th>
<td><select name="is_cool" id="id_is_cool" required>
<option value="1" selected="selected">Unknown</option>
<option value="1" selected>Unknown</option>
<option value="2">Yes</option>
<option value="3">No</option>
</select></td></tr>

View File

@ -110,24 +110,24 @@ class ModelFormCallableModelDefault(TestCase):
self.assertHTMLEqual(
ChoiceFieldForm().as_p(),
"""<p><label for="id_choice">Choice:</label> <select name="choice" id="id_choice" required>
<option value="1" selected="selected">ChoiceOption 1</option>
<option value="1" selected>ChoiceOption 1</option>
<option value="2">ChoiceOption 2</option>
<option value="3">ChoiceOption 3</option>
</select><input type="hidden" name="initial-choice" value="1" id="initial-id_choice" /></p>
<p><label for="id_choice_int">Choice int:</label> <select name="choice_int" id="id_choice_int" required>
<option value="1" selected="selected">ChoiceOption 1</option>
<option value="1" selected>ChoiceOption 1</option>
<option value="2">ChoiceOption 2</option>
<option value="3">ChoiceOption 3</option>
</select><input type="hidden" name="initial-choice_int" value="1" id="initial-id_choice_int" /></p>
<p><label for="id_multi_choice">Multi choice:</label>
<select multiple="multiple" name="multi_choice" id="id_multi_choice" required>
<option value="1" selected="selected">ChoiceOption 1</option>
<option value="1" selected>ChoiceOption 1</option>
<option value="2">ChoiceOption 2</option>
<option value="3">ChoiceOption 3</option>
</select><input type="hidden" name="initial-multi_choice" value="1" id="initial-id_multi_choice_0" /></p>
<p><label for="id_multi_choice_int">Multi choice int:</label>
<select multiple="multiple" name="multi_choice_int" id="id_multi_choice_int" required>
<option value="1" selected="selected">ChoiceOption 1</option>
<option value="1" selected>ChoiceOption 1</option>
<option value="2">ChoiceOption 2</option>
<option value="3">ChoiceOption 3</option>
</select><input type="hidden" name="initial-multi_choice_int" value="1" id="initial-id_multi_choice_int_0" /></p>"""
@ -147,26 +147,26 @@ class ModelFormCallableModelDefault(TestCase):
}).as_p(),
"""<p><label for="id_choice">Choice:</label> <select name="choice" id="id_choice" required>
<option value="1">ChoiceOption 1</option>
<option value="2" selected="selected">ChoiceOption 2</option>
<option value="2" selected>ChoiceOption 2</option>
<option value="3">ChoiceOption 3</option>
</select><input type="hidden" name="initial-choice" value="2" id="initial-id_choice" /></p>
<p><label for="id_choice_int">Choice int:</label> <select name="choice_int" id="id_choice_int" required>
<option value="1">ChoiceOption 1</option>
<option value="2" selected="selected">ChoiceOption 2</option>
<option value="2" selected>ChoiceOption 2</option>
<option value="3">ChoiceOption 3</option>
</select><input type="hidden" name="initial-choice_int" value="2" id="initial-id_choice_int" /></p>
<p><label for="id_multi_choice">Multi choice:</label>
<select multiple="multiple" name="multi_choice" id="id_multi_choice" required>
<option value="1">ChoiceOption 1</option>
<option value="2" selected="selected">ChoiceOption 2</option>
<option value="3" selected="selected">ChoiceOption 3</option>
<option value="2" selected>ChoiceOption 2</option>
<option value="3" selected>ChoiceOption 3</option>
</select><input type="hidden" name="initial-multi_choice" value="2" id="initial-id_multi_choice_0" />
<input type="hidden" name="initial-multi_choice" value="3" id="initial-id_multi_choice_1" /></p>
<p><label for="id_multi_choice_int">Multi choice int:</label>
<select multiple="multiple" name="multi_choice_int" id="id_multi_choice_int" required>
<option value="1">ChoiceOption 1</option>
<option value="2" selected="selected">ChoiceOption 2</option>
<option value="3" selected="selected">ChoiceOption 3</option>
<option value="2" selected>ChoiceOption 2</option>
<option value="3" selected>ChoiceOption 3</option>
</select><input type="hidden" name="initial-multi_choice_int" value="2" id="initial-id_multi_choice_int_0" />
<input type="hidden" name="initial-multi_choice_int" value="3" id="initial-id_multi_choice_int_1" /></p>"""
)
@ -310,7 +310,7 @@ class EmptyLabelTestCase(TestCase):
f.as_p(),
"""<p><label for="id_name">Name:</label> <input id="id_name" maxlength="10" name="name" type="text" required /></p>
<p><label for="id_choice">Choice:</label> <select id="id_choice" name="choice">
<option value="" selected="selected">No Preference</option>
<option value="" selected>No Preference</option>
<option value="f">Foo</option>
<option value="b">Bar</option>
</select></p>"""
@ -323,7 +323,7 @@ class EmptyLabelTestCase(TestCase):
"""<p><label for="id_name">Name:</label> <input id="id_name" maxlength="10" name="name" type="text" required /></p>
<p><label for="id_choice_string_w_none">Choice string w none:</label>
<select id="id_choice_string_w_none" name="choice_string_w_none">
<option value="" selected="selected">No Preference</option>
<option value="" selected>No Preference</option>
<option value="f">Foo</option>
<option value="b">Bar</option>
</select></p>"""
@ -353,7 +353,7 @@ class EmptyLabelTestCase(TestCase):
"""<p><label for="id_name">Name:</label> <input id="id_name" maxlength="10" name="name" type="text" required /></p>
<p><label for="id_choice_integer">Choice integer:</label>
<select id="id_choice_integer" name="choice_integer">
<option value="" selected="selected">No Preference</option>
<option value="" selected>No Preference</option>
<option value="1">Foo</option>
<option value="2">Bar</option>
</select></p>"""
@ -373,7 +373,7 @@ class EmptyLabelTestCase(TestCase):
<input id="id_name" maxlength="10" name="name" type="text" value="none-test" required /></p>
<p><label for="id_choice_integer">Choice integer:</label>
<select id="id_choice_integer" name="choice_integer">
<option value="" selected="selected">No Preference</option>
<option value="" selected>No Preference</option>
<option value="1">Foo</option>
<option value="2">Bar</option>
</select></p>"""
@ -388,7 +388,7 @@ class EmptyLabelTestCase(TestCase):
<p><label for="id_choice_integer">Choice integer:</label>
<select id="id_choice_integer" name="choice_integer">
<option value="">No Preference</option>
<option value="1" selected="selected">Foo</option>
<option value="1" selected>Foo</option>
<option value="2">Bar</option>
</select></p>"""
)

View File

@ -141,8 +141,8 @@ class MultiWidgetTest(WidgetTest):
"""
<input type="text" name="name_0" value="some text" />
<select multiple="multiple" name="name_1">
<option value="J" selected="selected">John</option>
<option value="P" selected="selected">Paul</option>
<option value="J" selected>John</option>
<option value="P" selected>Paul</option>
<option value="G">George</option>
<option value="R">Ringo</option>
</select>

View File

@ -12,7 +12,7 @@ class NullBooleanSelectTest(WidgetTest):
self.check_html(self.widget, 'is_cool', True, html=(
"""<select name="is_cool">
<option value="1">Unknown</option>
<option value="2" selected="selected">Yes</option>
<option value="2" selected>Yes</option>
<option value="3">No</option>
</select>"""
))
@ -22,14 +22,14 @@ class NullBooleanSelectTest(WidgetTest):
"""<select name="is_cool">
<option value="1">Unknown</option>
<option value="2">Yes</option>
<option value="3" selected="selected">No</option>
<option value="3" selected>No</option>
</select>"""
))
def test_render_none(self):
self.check_html(self.widget, 'is_cool', None, html=(
"""<select name="is_cool">
<option value="1" selected="selected">Unknown</option>
<option value="1" selected>Unknown</option>
<option value="2">Yes</option>
<option value="3">No</option>
</select>"""
@ -39,7 +39,7 @@ class NullBooleanSelectTest(WidgetTest):
self.check_html(self.widget, 'is_cool', '2', html=(
"""<select name="is_cool">
<option value="1">Unknown</option>
<option value="2" selected="selected">Yes</option>
<option value="2" selected>Yes</option>
<option value="3">No</option>
</select>"""
))
@ -57,7 +57,7 @@ class NullBooleanSelectTest(WidgetTest):
"""
<select name="id_bool">
<option value="1">Unbekannt</option>
<option value="2" selected="selected">Ja</option>
<option value="2" selected>Ja</option>
<option value="3">Nein</option>
</select>
"""

View File

@ -19,7 +19,7 @@ class SelectTest(WidgetTest):
def test_render(self):
self.check_html(self.widget(choices=self.beatles), 'beatle', 'J', html=(
"""<select name="beatle">
<option value="J" selected="selected">John</option>
<option value="J" selected>John</option>
<option value="P">Paul</option>
<option value="G">George</option>
<option value="R">Ringo</option>
@ -61,7 +61,7 @@ class SelectTest(WidgetTest):
self.check_html(self.widget(choices=choices), 'choices', '0', html=(
"""<select name="choices">
<option value="0" selected="selected">0</option>
<option value="0" selected>0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
@ -80,7 +80,7 @@ class SelectTest(WidgetTest):
self.check_html(widget, 'num', 2, html=(
"""<select name="num" class="super" id="super">
<option value="1">1</option>
<option value="2" selected="selected">2</option>
<option value="2" selected>2</option>
<option value="3">3</option>
</select>"""
))
@ -95,7 +95,7 @@ class SelectTest(WidgetTest):
html=(
"""<select name="num">
<option value="1">1</option>
<option value="2" selected="selected">2</option>
<option value="2" selected>2</option>
<option value="3">3</option>
</select>"""
),
@ -106,7 +106,7 @@ class SelectTest(WidgetTest):
html=(
"""<select name="num">
<option value="1">1</option>
<option value="2" selected="selected">2</option>
<option value="2" selected>2</option>
<option value="3">3</option>
</select>"""
),
@ -117,7 +117,7 @@ class SelectTest(WidgetTest):
html=(
"""<select name="num">
<option value="1">1</option>
<option value="2" selected="selected">2</option>
<option value="2" selected>2</option>
<option value="3">3</option>
</select>"""
),
@ -128,7 +128,7 @@ class SelectTest(WidgetTest):
self.check_html(widget, 'num', 2, html=(
"""<select name="num">
<option value="1">1</option>
<option value="2" selected="selected">2</option>
<option value="2" selected>2</option>
<option value="3">3</option>
</select>"""
))
@ -147,7 +147,7 @@ class SelectTest(WidgetTest):
"""<select name="num">
<option value="0">0</option>
<option value="1">1</option>
<option value="2" selected="selected">2</option>
<option value="2" selected>2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>"""
@ -157,7 +157,7 @@ class SelectTest(WidgetTest):
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3" selected="selected">3</option>
<option value="3" selected>3</option>
<option value="4">4</option>
</select>"""
))
@ -177,7 +177,7 @@ class SelectTest(WidgetTest):
'email', 'ŠĐĆŽćžšđ',
html=(
"""<select name="email">
<option value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" selected="selected">
<option value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" selected>
\u0160\u0110abc\u0106\u017d\u0107\u017e\u0161\u0111
</option>
<option value="\u0107\u017e\u0161\u0111">abc\u0107\u017e\u0161\u0111</option>
@ -202,7 +202,7 @@ class SelectTest(WidgetTest):
def test_choices_select_outer(self):
self.check_html(self.nested_widget, 'nestchoice', 'outer1', html=(
"""<select name="nestchoice">
<option value="outer1" selected="selected">Outer 1</option>
<option value="outer1" selected>Outer 1</option>
<optgroup label="Group &quot;1&quot;">
<option value="inner1">Inner 1</option>
<option value="inner2">Inner 2</option>
@ -215,7 +215,7 @@ class SelectTest(WidgetTest):
"""<select name="nestchoice">
<option value="outer1">Outer 1</option>
<optgroup label="Group &quot;1&quot;">
<option value="inner1" selected="selected">Inner 1</option>
<option value="inner1" selected>Inner 1</option>
<option value="inner2">Inner 2</option>
</optgroup>
</select>"""

View File

@ -101,7 +101,7 @@ class SelectDateWidgetTest(WidgetTest):
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4" selected="selected">April</option>
<option value="4" selected>April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
@ -128,7 +128,7 @@ class SelectDateWidgetTest(WidgetTest):
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15" selected="selected">15</option>
<option value="15" selected>15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
@ -152,7 +152,7 @@ class SelectDateWidgetTest(WidgetTest):
<option value="2007">2007</option>
<option value="2008">2008</option>
<option value="2009">2009</option>
<option value="2010" selected="selected">2010</option>
<option value="2010" selected>2010</option>
<option value="2011">2011</option>
<option value="2012">2012</option>
<option value="2013">2013</option>
@ -178,7 +178,7 @@ class SelectDateWidgetTest(WidgetTest):
<select name="mydate_month" id="id_mydate_month">
<option value="0">---</option>
<option value="1">January</option>
<option value="2" selected="selected">February</option>
<option value="2" selected>February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
@ -223,7 +223,7 @@ class SelectDateWidgetTest(WidgetTest):
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31" selected="selected">31</option>
<option value="31" selected>31</option>
</select>
<select name="mydate_year" id="id_mydate_year">
@ -231,7 +231,7 @@ class SelectDateWidgetTest(WidgetTest):
<option value="2007">2007</option>
<option value="2008">2008</option>
<option value="2009">2009</option>
<option value="2010" selected="selected">2010</option>
<option value="2010" selected>2010</option>
<option value="2011">2011</option>
<option value="2012">2012</option>
<option value="2013">2013</option>
@ -415,7 +415,7 @@ class SelectDateWidgetTest(WidgetTest):
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13" selected="selected">13</option>
<option value="13" selected>13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
@ -445,7 +445,7 @@ class SelectDateWidgetTest(WidgetTest):
<option value="5">mei</option>
<option value="6">juni</option>
<option value="7">juli</option>
<option value="8" selected="selected">augustus</option>
<option value="8" selected>augustus</option>
<option value="9">september</option>
<option value="10">oktober</option>
<option value="11">november</option>
@ -457,7 +457,7 @@ class SelectDateWidgetTest(WidgetTest):
<option value="2007">2007</option>
<option value="2008">2008</option>
<option value="2009">2009</option>
<option value="2010" selected="selected">2010</option>
<option value="2010" selected>2010</option>
<option value="2011">2011</option>
<option value="2012">2012</option>
<option value="2013">2013</option>
@ -469,7 +469,7 @@ class SelectDateWidgetTest(WidgetTest):
)
# Even with an invalid date, the widget should reflect the entered value (#17401).
self.assertEqual(w.render('mydate', '2010-02-30').count('selected="selected"'), 3)
self.assertEqual(w.render('mydate', '2010-02-30').count('selected'), 3)
# Years before 1900 should work.
w = SelectDateWidget(years=('1899',))

View File

@ -10,7 +10,7 @@ class SelectMultipleTest(WidgetTest):
def test_render_selected(self):
self.check_html(self.widget(choices=self.beatles), 'beatles', ['J'], html=(
"""<select multiple="multiple" name="beatles">
<option value="J" selected="selected">John</option>
<option value="J" selected>John</option>
<option value="P">Paul</option>
<option value="G">George</option>
<option value="R">Ringo</option>
@ -20,8 +20,8 @@ class SelectMultipleTest(WidgetTest):
def test_render_multiple_selected(self):
self.check_html(self.widget(choices=self.beatles), 'beatles', ['J', 'P'], html=(
"""<select multiple="multiple" name="beatles">
<option value="J" selected="selected">John</option>
<option value="P" selected="selected">Paul</option>
<option value="J" selected>John</option>
<option value="P" selected>Paul</option>
<option value="G">George</option>
<option value="R">Ringo</option>
</select>"""
@ -60,11 +60,11 @@ class SelectMultipleTest(WidgetTest):
"""
self.check_html(self.widget(choices=self.numeric_choices), 'choices', ['0'], html=(
"""<select multiple="multiple" name="choices">
<option value="0" selected="selected">0</option>
<option value="0" selected>0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="0" selected="selected">extra</option>
<option value="0" selected>extra</option>
</select>"""
))
@ -75,9 +75,9 @@ class SelectMultipleTest(WidgetTest):
"""
self.check_html(self.widget(choices=self.beatles), 'beatles', ['J', 'G', 'foo'], html=(
"""<select multiple="multiple" name="beatles">
<option value="J" selected="selected">John</option>
<option value="J" selected>John</option>
<option value="P">Paul</option>
<option value="G" selected="selected">George</option>
<option value="G" selected>George</option>
<option value="R">Ringo</option>
</select>"""
))
@ -88,7 +88,7 @@ class SelectMultipleTest(WidgetTest):
self.check_html(self.widget(choices=choices), 'nums', [2], html=(
"""<select multiple="multiple" name="nums">
<option value="1">1</option>
<option value="2" selected="selected">2</option>
<option value="2" selected>2</option>
<option value="3">3</option>
</select>"""
))
@ -96,7 +96,7 @@ class SelectMultipleTest(WidgetTest):
self.check_html(self.widget(choices=choices), 'nums', ['2'], html=(
"""<select multiple="multiple" name="nums">
<option value="1">1</option>
<option value="2" selected="selected">2</option>
<option value="2" selected>2</option>
<option value="3">3</option>
</select>"""
))
@ -104,7 +104,7 @@ class SelectMultipleTest(WidgetTest):
self.check_html(self.widget(choices=choices), 'nums', [2], html=(
"""<select multiple="multiple" name="nums">
<option value="1">1</option>
<option value="2" selected="selected">2</option>
<option value="2" selected>2</option>
<option value="3">3</option>
</select>"""
))
@ -116,10 +116,10 @@ class SelectMultipleTest(WidgetTest):
))
self.check_html(widget, 'nestchoice', ['outer1', 'inner2'], html=(
"""<select multiple="multiple" name="nestchoice">
<option value="outer1" selected="selected">Outer 1</option>
<option value="outer1" selected>Outer 1</option>
<optgroup label="Group &quot;1&quot;">
<option value="inner1">Inner 1</option>
<option value="inner2" selected="selected">Inner 2</option>
<option value="inner2" selected>Inner 2</option>
</optgroup>
</select>"""
))

View File

@ -664,7 +664,7 @@ class FormattingTests(SimpleTestCase):
'<option value="9">setembre</option>'
'<option value="10">octubre</option>'
'<option value="11">novembre</option>'
'<option value="12" selected="selected">desembre</option>'
'<option value="12" selected>desembre</option>'
'</select>'
'<select name="mydate_day" id="id_mydate_day">'
'<option value="0">---</option>'
@ -698,11 +698,11 @@ class FormattingTests(SimpleTestCase):
'<option value="28">28</option>'
'<option value="29">29</option>'
'<option value="30">30</option>'
'<option value="31" selected="selected">31</option>'
'<option value="31" selected>31</option>'
'</select>'
'<select name="mydate_year" id="id_mydate_year">'
'<option value="0">---</option>'
'<option value="2009" selected="selected">2009</option>'
'<option value="2009" selected>2009</option>'
'<option value="2010">2010</option>'
'<option value="2011">2011</option>'
'<option value="2012">2012</option>'
@ -864,7 +864,7 @@ class FormattingTests(SimpleTestCase):
'<option value="28">28</option>'
'<option value="29">29</option>'
'<option value="30">30</option>'
'<option value="31" selected="selected">31</option>'
'<option value="31" selected>31</option>'
'</select>'
'<select name="mydate_month" id="id_mydate_month">'
'<option value="0">---</option>'
@ -879,11 +879,11 @@ class FormattingTests(SimpleTestCase):
'<option value="9">setembre</option>'
'<option value="10">octubre</option>'
'<option value="11">novembre</option>'
'<option value="12" selected="selected">desembre</option>'
'<option value="12" selected>desembre</option>'
'</select>'
'<select name="mydate_year" id="id_mydate_year">'
'<option value="0">---</option>'
'<option value="2009" selected="selected">2009</option>'
'<option value="2009" selected>2009</option>'
'<option value="2010">2010</option>'
'<option value="2011">2011</option>'
'<option value="2012">2012</option>'
@ -932,7 +932,7 @@ class FormattingTests(SimpleTestCase):
'<option value="28">28</option>'
'<option value="29">29</option>'
'<option value="30">30</option>'
'<option value="31" selected="selected">31</option>'
'<option value="31" selected>31</option>'
'</select>'
'<select name="mydate_month" id="id_mydate_month">'
'<option value="0">---</option>'
@ -947,11 +947,11 @@ class FormattingTests(SimpleTestCase):
'<option value="9">\u0421\u0435\u043d\u0442\u044f\u0431\u0440\u044c</option>'
'<option value="10">\u041e\u043a\u0442\u044f\u0431\u0440\u044c</option>'
'<option value="11">\u041d\u043e\u044f\u0431\u0440\u044c</option>'
'<option value="12" selected="selected">\u0414\u0435\u043a\u0430\u0431\u0440\u044c</option>'
'<option value="12" selected>\u0414\u0435\u043a\u0430\u0431\u0440\u044c</option>'
'</select>'
'<select name="mydate_year" id="id_mydate_year">'
'<option value="0">---</option>'
'<option value="2009" selected="selected">2009</option>'
'<option value="2009" selected>2009</option>'
'<option value="2010">2010</option>'
'<option value="2011">2011</option>'
'<option value="2012">2012</option>'
@ -1042,7 +1042,7 @@ class FormattingTests(SimpleTestCase):
'<option value="9">September</option>'
'<option value="10">October</option>'
'<option value="11">November</option>'
'<option value="12" selected="selected">December</option>'
'<option value="12" selected>December</option>'
'</select>'
'<select name="mydate_day" id="id_mydate_day">'
'<option value="0">---</option>'
@ -1076,11 +1076,11 @@ class FormattingTests(SimpleTestCase):
'<option value="28">28</option>'
'<option value="29">29</option>'
'<option value="30">30</option>'
'<option value="31" selected="selected">31</option>'
'<option value="31" selected>31</option>'
'</select>'
'<select name="mydate_year" id="id_mydate_year">'
'<option value="0">---</option>'
'<option value="2009" selected="selected">2009</option>'
'<option value="2009" selected>2009</option>'
'<option value="2010">2010</option>'
'<option value="2011">2011</option>'
'<option value="2012">2012</option>'

View File

@ -1075,18 +1075,18 @@ class ModelFormBasicTests(TestCase):
<li>Slug: <input type="text" name="slug" maxlength="50" required /></li>
<li>Pub date: <input type="text" name="pub_date" required /></li>
<li>Writer: <select name="writer" required>
<option value="" selected="selected">---------</option>
<option value="" selected>---------</option>
<option value="%s">Bob Woodward</option>
<option value="%s">Mike Royko</option>
</select></li>
<li>Article: <textarea rows="10" cols="40" name="article" required></textarea></li>
<li>Categories: <select multiple="multiple" name="categories">
<option value="%s" selected="selected">Entertainment</option>
<option value="%s" selected="selected">It&#39;s a test</option>
<option value="%s" selected>Entertainment</option>
<option value="%s" selected>It&#39;s a test</option>
<option value="%s">Third test</option>
</select></li>
<li>Status: <select name="status">
<option value="" selected="selected">---------</option>
<option value="" selected>---------</option>
<option value="1">Draft</option>
<option value="2">Pending</option>
<option value="3">Live</option>
@ -1119,7 +1119,7 @@ class ModelFormBasicTests(TestCase):
<li>Writer: <select name="writer" required>
<option value="">---------</option>
<option value="%s">Bob Woodward</option>
<option value="%s" selected="selected">Mike Royko</option>
<option value="%s" selected>Mike Royko</option>
</select></li>
<li>Article: <textarea rows="10" cols="40" name="article" required>Hello.</textarea></li>
<li>Categories: <select multiple="multiple" name="categories">
@ -1128,7 +1128,7 @@ class ModelFormBasicTests(TestCase):
<option value="%s">Third test</option>
</select></li>
<li>Status: <select name="status">
<option value="" selected="selected">---------</option>
<option value="" selected>---------</option>
<option value="1">Draft</option>
<option value="2">Pending</option>
<option value="3">Live</option>
@ -1171,8 +1171,8 @@ class ModelFormBasicTests(TestCase):
<input id="id_headline" type="text" name="headline" maxlength="50" required /></li>
<li><label for="id_categories">Categories:</label>
<select multiple="multiple" name="categories" id="id_categories">
<option value="%d" selected="selected">Entertainment</option>
<option value="%d" selected="selected">It&39;s a test</option>
<option value="%d" selected>Entertainment</option>
<option value="%d" selected>It&39;s a test</option>
<option value="%d">Third test</option>
</select></li>"""
% (self.c1.pk, self.c2.pk, self.c3.pk))
@ -1233,7 +1233,7 @@ class ModelFormBasicTests(TestCase):
<tr><th>Slug:</th><td><input type="text" name="slug" maxlength="50" required /></td></tr>
<tr><th>Pub date:</th><td><input type="text" name="pub_date" required /></td></tr>
<tr><th>Writer:</th><td><select name="writer" required>
<option value="" selected="selected">---------</option>
<option value="" selected>---------</option>
<option value="%s">Bob Woodward</option>
<option value="%s">Mike Royko</option>
</select></td></tr>
@ -1244,7 +1244,7 @@ class ModelFormBasicTests(TestCase):
<option value="%s">Third test</option>
</select></td></tr>
<tr><th>Status:</th><td><select name="status">
<option value="" selected="selected">---------</option>
<option value="" selected>---------</option>
<option value="1">Draft</option>
<option value="2">Pending</option>
<option value="3">Live</option>
@ -1265,16 +1265,16 @@ class ModelFormBasicTests(TestCase):
<li>Writer: <select name="writer" required>
<option value="">---------</option>
<option value="%s">Bob Woodward</option>
<option value="%s" selected="selected">Mike Royko</option>
<option value="%s" selected>Mike Royko</option>
</select></li>
<li>Article: <textarea rows="10" cols="40" name="article" required>Hello.</textarea></li>
<li>Categories: <select multiple="multiple" name="categories">
<option value="%s" selected="selected">Entertainment</option>
<option value="%s" selected>Entertainment</option>
<option value="%s">It&#39;s a test</option>
<option value="%s">Third test</option>
</select></li>
<li>Status: <select name="status">
<option value="" selected="selected">---------</option>
<option value="" selected>---------</option>
<option value="1">Draft</option>
<option value="2">Pending</option>
<option value="3">Live</option>
@ -1409,7 +1409,7 @@ class ModelFormBasicTests(TestCase):
<li>Slug: <input type="text" name="slug" maxlength="50" required /></li>
<li>Pub date: <input type="text" name="pub_date" required /></li>
<li>Writer: <select name="writer" required>
<option value="" selected="selected">---------</option>
<option value="" selected>---------</option>
<option value="%s">Bob Woodward</option>
<option value="%s">Mike Royko</option>
</select></li>
@ -1420,7 +1420,7 @@ class ModelFormBasicTests(TestCase):
<option value="%s">Third test</option>
</select> </li>
<li>Status: <select name="status">
<option value="" selected="selected">---------</option>
<option value="" selected>---------</option>
<option value="1">Draft</option>
<option value="2">Pending</option>
<option value="3">Live</option>
@ -1434,7 +1434,7 @@ class ModelFormBasicTests(TestCase):
<li>Slug: <input type="text" name="slug" maxlength="50" required /></li>
<li>Pub date: <input type="text" name="pub_date" required /></li>
<li>Writer: <select name="writer" required>
<option value="" selected="selected">---------</option>
<option value="" selected>---------</option>
<option value="%s">Bob Woodward</option>
<option value="%s">Carl Bernstein</option>
<option value="%s">Mike Royko</option>
@ -1447,7 +1447,7 @@ class ModelFormBasicTests(TestCase):
<option value="%s">Fourth</option>
</select></li>
<li>Status: <select name="status">
<option value="" selected="selected">---------</option>
<option value="" selected>---------</option>
<option value="1">Draft</option>
<option value="2">Pending</option>
<option value="3">Live</option>
@ -1911,7 +1911,7 @@ class ModelOneToOneFieldTests(TestCase):
self.assertHTMLEqual(
form.as_p(),
'''<p><label for="id_writer">Writer:</label> <select name="writer" id="id_writer" required>
<option value="" selected="selected">---------</option>
<option value="" selected>---------</option>
<option value="%s">Bob Woodward</option>
<option value="%s">Mike Royko</option>
</select></p>
@ -1933,7 +1933,7 @@ class ModelOneToOneFieldTests(TestCase):
form.as_p(),
'''<p><label for="id_writer">Writer:</label> <select name="writer" id="id_writer" required>
<option value="">---------</option>
<option value="%s" selected="selected">Bob Woodward</option>
<option value="%s" selected>Bob Woodward</option>
<option value="%s">Mike Royko</option>
</select></p>
<p><label for="id_age">Age:</label>
@ -2493,7 +2493,7 @@ class OtherModelFormTests(TestCase):
form = InventoryForm(instance=core)
self.assertHTMLEqual(six.text_type(form['parent']), '''<select name="parent" id="id_parent">
<option value="">---------</option>
<option value="86" selected="selected">Apple</option>
<option value="86" selected>Apple</option>
<option value="87">Core</option>
<option value="22">Pear</option>
</select>''')
@ -2576,13 +2576,13 @@ class OtherModelFormTests(TestCase):
<input id="id_date_published" name="date_published" type="text" value="{0}" required />
<input id="initial-id_date_published" name="initial-date_published" type="hidden" value="{0}" /></p>
<p><label for="id_mode">Mode:</label> <select id="id_mode" name="mode" required>
<option value="di" selected="selected">direct</option>
<option value="di" selected>direct</option>
<option value="de">delayed</option></select>
<input id="initial-id_mode" name="initial-mode" type="hidden" value="di" /></p>
<p><label for="id_category">Category:</label> <select id="id_category" name="category" required>
<option value="1">Games</option>
<option value="2">Comics</option>
<option value="3" selected="selected">Novel</option></select>
<option value="3" selected>Novel</option></select>
<input id="initial-id_category" name="initial-category" type="hidden" value="3" />
""".format(today_str)
)

View File

@ -1134,7 +1134,7 @@ class ModelFormsetTest(TestCase):
formset.forms[0].as_p(),
'<p><label for="id_form-0-owner">Owner:</label>'
'<select name="form-0-owner" id="id_form-0-owner">'
'<option value="" selected="selected">---------</option>'
'<option value="" selected>---------</option>'
'<option value="%d">Joe Perry at Giordanos</option>'
'<option value="%d">Jack Berry at Giordanos</option>'
'</select></p>'

View File

@ -360,7 +360,7 @@ class ModelAdminTests(TestCase):
str(form["main_band"]),
'<div class="related-widget-wrapper">'
'<select name="main_band" id="id_main_band" required>'
'<option value="" selected="selected">---------</option>'
'<option value="" selected>---------</option>'
'<option value="%d">The Beatles</option>'
'<option value="%d">The Doors</option>'
'</select></div>' % (band2.id, self.band.id)
@ -381,7 +381,7 @@ class ModelAdminTests(TestCase):
str(form["main_band"]),
'<div class="related-widget-wrapper">'
'<select name="main_band" id="id_main_band" required>'
'<option value="" selected="selected">---------</option>'
'<option value="" selected>---------</option>'
'<option value="%d">The Doors</option>'
'</select></div>' % self.band.id
)