diff --git a/django/newforms/widgets.py b/django/newforms/widgets.py
index ebbf2ab..37d08e1 100644
a
|
b
|
class RadioFieldRenderer(StrAndUnicode):
|
321 | 321 | |
322 | 322 | def render(self): |
323 | 323 | """Outputs a <ul> for this set of radio fields.""" |
324 | | return mark_safe(u'<ul>\n%s\n</ul>' % u'\n'.join([u'<li>%s</li>' |
325 | | % force_unicode(w) for w in self])) |
| 324 | att = {} |
| 325 | id_ = self.attrs.get('id') |
| 326 | if id_: |
| 327 | att['id'] = id_ |
| 328 | return mark_safe(u'<ul%s>\n%s\n</ul>' % (flatatt(att), u'\n'.join([u'<li>%s</li>' |
| 329 | % force_unicode(w) for w in self]))) |
326 | 330 | |
327 | 331 | class RadioSelect(Select): |
328 | 332 | renderer = RadioFieldRenderer |
… |
… |
class CheckboxSelectMultiple(SelectMultiple):
|
360 | 364 | if value is None: value = [] |
361 | 365 | has_id = attrs and 'id' in attrs |
362 | 366 | final_attrs = self.build_attrs(attrs, name=name) |
363 | | output = [u'<ul>'] |
| 367 | att = {} |
| 368 | id_ = final_attrs.get('id') |
| 369 | if id_: |
| 370 | att['id'] = id_ |
| 371 | output = [u'<ul%s>' % flatatt(att)] |
364 | 372 | # Normalize to strings |
365 | 373 | str_values = set([force_unicode(v) for v in value]) |
366 | 374 | for i, (option_value, option_label) in enumerate(chain(self.choices, choices)): |
diff --git a/tests/regressiontests/forms/forms.py b/tests/regressiontests/forms/forms.py
index 7fc206d..1ef290f 100644
a
|
b
|
gets a distinct ID, formed by appending an underscore plus the button's
|
442 | 442 | zero-based index. |
443 | 443 | >>> f = FrameworkForm(auto_id='id_%s') |
444 | 444 | >>> print f['language'] |
445 | | <ul> |
| 445 | <ul id="id_language"> |
446 | 446 | <li><label for="id_language_0"><input type="radio" id="id_language_0" value="P" name="language" /> Python</label></li> |
447 | 447 | <li><label for="id_language_1"><input type="radio" id="id_language_1" value="J" name="language" /> Java</label></li> |
448 | 448 | </ul> |
… |
… |
either as_table() or as_ul(), the label for the RadioSelect will point to the
|
452 | 452 | ID of the *first* radio button. |
453 | 453 | >>> print f |
454 | 454 | <tr><th><label for="id_name">Name:</label></th><td><input type="text" name="name" id="id_name" /></td></tr> |
455 | | <tr><th><label for="id_language_0">Language:</label></th><td><ul> |
| 455 | <tr><th><label for="id_language_0">Language:</label></th><td><ul id="id_language"> |
456 | 456 | <li><label for="id_language_0"><input type="radio" id="id_language_0" value="P" name="language" /> Python</label></li> |
457 | 457 | <li><label for="id_language_1"><input type="radio" id="id_language_1" value="J" name="language" /> Java</label></li> |
458 | 458 | </ul></td></tr> |
459 | 459 | >>> print f.as_ul() |
460 | 460 | <li><label for="id_name">Name:</label> <input type="text" name="name" id="id_name" /></li> |
461 | | <li><label for="id_language_0">Language:</label> <ul> |
| 461 | <li><label for="id_language_0">Language:</label> <ul id="id_language"> |
462 | 462 | <li><label for="id_language_0"><input type="radio" id="id_language_0" value="P" name="language" /> Python</label></li> |
463 | 463 | <li><label for="id_language_1"><input type="radio" id="id_language_1" value="J" name="language" /> Java</label></li> |
464 | 464 | </ul></li> |
465 | 465 | >>> print f.as_p() |
466 | 466 | <p><label for="id_name">Name:</label> <input type="text" name="name" id="id_name" /></p> |
467 | | <p><label for="id_language_0">Language:</label> <ul> |
| 467 | <p><label for="id_language_0">Language:</label> <ul id="id_language"> |
468 | 468 | <li><label for="id_language_0"><input type="radio" id="id_language_0" value="P" name="language" /> Python</label></li> |
469 | 469 | <li><label for="id_language_1"><input type="radio" id="id_language_1" value="J" name="language" /> Java</label></li> |
470 | 470 | </ul></p> |
… |
… |
gets a distinct ID, formed by appending an underscore plus the checkbox's
|
534 | 534 | zero-based index. |
535 | 535 | >>> f = SongForm(auto_id='%s_id') |
536 | 536 | >>> print f['composers'] |
537 | | <ul> |
| 537 | <ul id="composers_id"> |
538 | 538 | <li><label for="composers_id_0"><input type="checkbox" name="composers" value="J" id="composers_id_0" /> John Lennon</label></li> |
539 | 539 | <li><label for="composers_id_1"><input type="checkbox" name="composers" value="P" id="composers_id_1" /> Paul McCartney</label></li> |
540 | 540 | </ul> |
diff --git a/tests/regressiontests/forms/regressions.py b/tests/regressiontests/forms/regressions.py
index cbc8095..0f634d7 100644
a
|
b
|
Unicode decoding problems...
|
40 | 40 | ... somechoice = ChoiceField(choices=GENDERS, widget=RadioSelect(), label=u'\xc5\xf8\xdf') |
41 | 41 | >>> f = SomeForm() |
42 | 42 | >>> f.as_p() |
43 | | 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>' |
| 43 | 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>' |
44 | 44 | |
45 | 45 | Testing choice validation with UTF-8 bytestrings as input (these are the |
46 | 46 | Russian abbreviations "мес." and "шт.". |
… |
… |
Translated error messages used to be buggy.
|
56 | 56 | >>> activate('ru') |
57 | 57 | >>> f = SomeForm({}) |
58 | 58 | >>> f.as_p() |
59 | | 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>' |
| 59 | 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>' |
60 | 60 | >>> deactivate() |
61 | 61 | |
62 | 62 | Deep copying translated text shouldn't raise an error |
diff --git a/tests/regressiontests/forms/widgets.py b/tests/regressiontests/forms/widgets.py
index 2c6b51a..d0ad268 100644
a
|
b
|
u'<ul>\n<li><label><input checked="checked" type="radio" name="email" value="\u0
|
740 | 740 | # Attributes provided at instantiation are passed to the constituent inputs |
741 | 741 | >>> w = RadioSelect(attrs={'id':'foo'}) |
742 | 742 | >>> print w.render('beatle', 'J', choices=(('J', 'John'), ('P', 'Paul'), ('G', 'George'), ('R', 'Ringo'))) |
743 | | <ul> |
| 743 | <ul id="foo"> |
744 | 744 | <li><label for="foo_0"><input checked="checked" type="radio" id="foo_0" value="J" name="beatle" /> John</label></li> |
745 | 745 | <li><label for="foo_1"><input type="radio" id="foo_1" value="P" name="beatle" /> Paul</label></li> |
746 | 746 | <li><label for="foo_2"><input type="radio" id="foo_2" value="G" name="beatle" /> George</label></li> |
… |
… |
u'<ul>\n<li><label><input checked="checked" type="radio" name="email" value="\u0
|
750 | 750 | # Attributes provided at render-time are passed to the constituent inputs |
751 | 751 | >>> w = RadioSelect() |
752 | 752 | >>> print w.render('beatle', 'J', choices=(('J', 'John'), ('P', 'Paul'), ('G', 'George'), ('R', 'Ringo')), attrs={'id':'bar'}) |
753 | | <ul> |
| 753 | <ul id="bar"> |
754 | 754 | <li><label for="bar_0"><input checked="checked" type="radio" id="bar_0" value="J" name="beatle" /> John</label></li> |
755 | 755 | <li><label for="bar_1"><input type="radio" id="bar_1" value="P" name="beatle" /> Paul</label></li> |
756 | 756 | <li><label for="bar_2"><input type="radio" id="bar_2" value="G" name="beatle" /> George</label></li> |