Code

Ticket #4117: widget-ul.2.diff

File widget-ul.2.diff, 8.1 KB (added by Alex, 6 years ago)

No more test failures

Line 
1diff --git a/django/newforms/widgets.py b/django/newforms/widgets.py
2index ebbf2ab..5a830e3 100644
3--- a/django/newforms/widgets.py
4+++ b/django/newforms/widgets.py
5@@ -321,8 +321,8 @@ class RadioFieldRenderer(StrAndUnicode):
6 
7     def render(self):
8         """Outputs a <ul> for this set of radio fields."""
9-        return mark_safe(u'<ul>\n%s\n</ul>' % u'\n'.join([u'<li>%s</li>'
10-                % force_unicode(w) for w in self]))
11+        return mark_safe(u'<ul%s>\n%s\n</ul>' % (flatatt(self.attrs), u'\n'.join([u'<li>%s</li>'
12+                % force_unicode(w) for w in self])))
13 
14 class RadioSelect(Select):
15     renderer = RadioFieldRenderer
16@@ -360,7 +360,7 @@ class CheckboxSelectMultiple(SelectMultiple):
17         if value is None: value = []
18         has_id = attrs and 'id' in attrs
19         final_attrs = self.build_attrs(attrs, name=name)
20-        output = [u'<ul>']
21+        output = [u'<ul%s>' % flatatt(self.build_attrs(attrs))]
22         # Normalize to strings
23         str_values = set([force_unicode(v) for v in value])
24         for i, (option_value, option_label) in enumerate(chain(self.choices, choices)):
25diff --git a/tests/regressiontests/forms/forms.py b/tests/regressiontests/forms/forms.py
26index 7fc206d..1ef290f 100644
27--- a/tests/regressiontests/forms/forms.py
28+++ b/tests/regressiontests/forms/forms.py
29@@ -442,7 +442,7 @@ gets a distinct ID, formed by appending an underscore plus the button's
30 zero-based index.
31 >>> f = FrameworkForm(auto_id='id_%s')
32 >>> print f['language']
33-<ul>
34+<ul id="id_language">
35 <li><label for="id_language_0"><input type="radio" id="id_language_0" value="P" name="language" /> Python</label></li>
36 <li><label for="id_language_1"><input type="radio" id="id_language_1" value="J" name="language" /> Java</label></li>
37 </ul>
38@@ -452,19 +452,19 @@ either as_table() or as_ul(), the label for the RadioSelect will point to the
39 ID of the *first* radio button.
40 >>> print f
41 <tr><th><label for="id_name">Name:</label></th><td><input type="text" name="name" id="id_name" /></td></tr>
42-<tr><th><label for="id_language_0">Language:</label></th><td><ul>
43+<tr><th><label for="id_language_0">Language:</label></th><td><ul id="id_language">
44 <li><label for="id_language_0"><input type="radio" id="id_language_0" value="P" name="language" /> Python</label></li>
45 <li><label for="id_language_1"><input type="radio" id="id_language_1" value="J" name="language" /> Java</label></li>
46 </ul></td></tr>
47 >>> print f.as_ul()
48 <li><label for="id_name">Name:</label> <input type="text" name="name" id="id_name" /></li>
49-<li><label for="id_language_0">Language:</label> <ul>
50+<li><label for="id_language_0">Language:</label> <ul id="id_language">
51 <li><label for="id_language_0"><input type="radio" id="id_language_0" value="P" name="language" /> Python</label></li>
52 <li><label for="id_language_1"><input type="radio" id="id_language_1" value="J" name="language" /> Java</label></li>
53 </ul></li>
54 >>> print f.as_p()
55 <p><label for="id_name">Name:</label> <input type="text" name="name" id="id_name" /></p>
56-<p><label for="id_language_0">Language:</label> <ul>
57+<p><label for="id_language_0">Language:</label> <ul id="id_language">
58 <li><label for="id_language_0"><input type="radio" id="id_language_0" value="P" name="language" /> Python</label></li>
59 <li><label for="id_language_1"><input type="radio" id="id_language_1" value="J" name="language" /> Java</label></li>
60 </ul></p>
61@@ -534,7 +534,7 @@ gets a distinct ID, formed by appending an underscore plus the checkbox's
62 zero-based index.
63 >>> f = SongForm(auto_id='%s_id')
64 >>> print f['composers']
65-<ul>
66+<ul id="composers_id">
67 <li><label for="composers_id_0"><input type="checkbox" name="composers" value="J" id="composers_id_0" /> John Lennon</label></li>
68 <li><label for="composers_id_1"><input type="checkbox" name="composers" value="P" id="composers_id_1" /> Paul McCartney</label></li>
69 </ul>
70diff --git a/tests/regressiontests/forms/regressions.py b/tests/regressiontests/forms/regressions.py
71index cbc8095..0f634d7 100644
72--- a/tests/regressiontests/forms/regressions.py
73+++ b/tests/regressiontests/forms/regressions.py
74@@ -40,7 +40,7 @@ Unicode decoding problems...
75 ...     somechoice = ChoiceField(choices=GENDERS, widget=RadioSelect(), label=u'\xc5\xf8\xdf')
76 >>> f = SomeForm()
77 >>> f.as_p()
78-u'<p><label for="id_somechoice_0">\xc5\xf8\xdf:</label> <ul>\n<li><label for="id_somechoice_0"><input type="radio" id="id_somechoice_0" value="\xc5" name="somechoice" /> En tied\xe4</label></li>\n<li><label for="id_somechoice_1"><input type="radio" id="id_somechoice_1" value="\xf8" name="somechoice" /> Mies</label></li>\n<li><label for="id_somechoice_2"><input type="radio" id="id_somechoice_2" value="\xdf" name="somechoice" /> Nainen</label></li>\n</ul></p>'
79+u'<p><label for="id_somechoice_0">\xc5\xf8\xdf:</label> <ul id="id_somechoice">\n<li><label for="id_somechoice_0"><input type="radio" id="id_somechoice_0" value="\xc5" name="somechoice" /> En tied\xe4</label></li>\n<li><label for="id_somechoice_1"><input type="radio" id="id_somechoice_1" value="\xf8" name="somechoice" /> Mies</label></li>\n<li><label for="id_somechoice_2"><input type="radio" id="id_somechoice_2" value="\xdf" name="somechoice" /> Nainen</label></li>\n</ul></p>'
80 
81 Testing choice validation with UTF-8 bytestrings as input (these are the
82 Russian abbreviations "мес." and "шт.".
83@@ -56,7 +56,7 @@ Translated error messages used to be buggy.
84 >>> activate('ru')
85 >>> f = SomeForm({})
86 >>> f.as_p()
87-u'<ul class="errorlist"><li>\u041e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u043f\u043e\u043b\u0435.</li></ul>\n<p><label for="id_somechoice_0">\xc5\xf8\xdf:</label> <ul>\n<li><label for="id_somechoice_0"><input type="radio" id="id_somechoice_0" value="\xc5" name="somechoice" /> En tied\xe4</label></li>\n<li><label for="id_somechoice_1"><input type="radio" id="id_somechoice_1" value="\xf8" name="somechoice" /> Mies</label></li>\n<li><label for="id_somechoice_2"><input type="radio" id="id_somechoice_2" value="\xdf" name="somechoice" /> Nainen</label></li>\n</ul></p>'
88+u'<ul class="errorlist"><li>\u041e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u043f\u043e\u043b\u0435.</li></ul>\n<p><label for="id_somechoice_0">\xc5\xf8\xdf:</label> <ul id="id_somechoice">\n<li><label for="id_somechoice_0"><input type="radio" id="id_somechoice_0" value="\xc5" name="somechoice" /> En tied\xe4</label></li>\n<li><label for="id_somechoice_1"><input type="radio" id="id_somechoice_1" value="\xf8" name="somechoice" /> Mies</label></li>\n<li><label for="id_somechoice_2"><input type="radio" id="id_somechoice_2" value="\xdf" name="somechoice" /> Nainen</label></li>\n</ul></p>'
89 >>> deactivate()
90 
91 Deep copying translated text shouldn't raise an error
92diff --git a/tests/regressiontests/forms/widgets.py b/tests/regressiontests/forms/widgets.py
93index 2c6b51a..d0ad268 100644
94--- a/tests/regressiontests/forms/widgets.py
95+++ b/tests/regressiontests/forms/widgets.py
96@@ -740,7 +740,7 @@ u'<ul>\n<li><label><input checked="checked" type="radio" name="email" value="\u0
97 # Attributes provided at instantiation are passed to the constituent inputs
98 >>> w = RadioSelect(attrs={'id':'foo'})
99 >>> print w.render('beatle', 'J', choices=(('J', 'John'), ('P', 'Paul'), ('G', 'George'), ('R', 'Ringo')))
100-<ul>
101+<ul id="foo">
102 <li><label for="foo_0"><input checked="checked" type="radio" id="foo_0" value="J" name="beatle" /> John</label></li>
103 <li><label for="foo_1"><input type="radio" id="foo_1" value="P" name="beatle" /> Paul</label></li>
104 <li><label for="foo_2"><input type="radio" id="foo_2" value="G" name="beatle" /> George</label></li>
105@@ -750,7 +750,7 @@ u'<ul>\n<li><label><input checked="checked" type="radio" name="email" value="\u0
106 # Attributes provided at render-time are passed to the constituent inputs
107 >>> w = RadioSelect()
108 >>> print w.render('beatle', 'J', choices=(('J', 'John'), ('P', 'Paul'), ('G', 'George'), ('R', 'Ringo')), attrs={'id':'bar'})
109-<ul>
110+<ul id="bar">
111 <li><label for="bar_0"><input checked="checked" type="radio" id="bar_0" value="J" name="beatle" /> John</label></li>
112 <li><label for="bar_1"><input type="radio" id="bar_1" value="P" name="beatle" /> Paul</label></li>
113 <li><label for="bar_2"><input type="radio" id="bar_2" value="G" name="beatle" /> George</label></li>