summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2011-12-07 22:31:39 +0000
committerAdrian Holovaty <adrian@holovaty.com>2011-12-07 22:31:39 +0000
commitfc90c09efdfbc029d43e6d4c0952ed6b49f6f34d (patch)
treeb86bdd032d4afc93cb3135312377cf02532dc68d /tests
parent0519adb2a87090bd9ee3f61c7b9a6ff6de5fa341 (diff)
Made BoundFields iterable, so that you can iterate over individual radio buttons of a RadioSelect in a template
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17173 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/regressiontests/forms/tests/forms.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/regressiontests/forms/tests/forms.py b/tests/regressiontests/forms/tests/forms.py
index a37cc2e3cb..3cedb04b94 100644
--- a/tests/regressiontests/forms/tests/forms.py
+++ b/tests/regressiontests/forms/tests/forms.py
@@ -434,6 +434,28 @@ class FormsTestCase(TestCase):
<li><label for="id_language_1"><input type="radio" id="id_language_1" value="J" name="language" /> Java</label></li>
</ul></p>""")
+ def test_form_with_iterable_boundfield(self):
+ class BeatleForm(Form):
+ name = ChoiceField(choices=[('john', 'John'), ('paul', 'Paul'), ('george', 'George'), ('ringo', 'Ringo')], widget=RadioSelect)
+
+ f = BeatleForm(auto_id=False)
+ self.assertEqual('\n'.join(list(f['name'])), """<label><input type="radio" name="name" value="john" /> John</label>
+<label><input type="radio" name="name" value="paul" /> Paul</label>
+<label><input type="radio" name="name" value="george" /> George</label>
+<label><input type="radio" name="name" value="ringo" /> Ringo</label>""")
+ self.assertEqual('\n'.join(['<div>%s</div>' % bf for bf in f['name']]), """<div><label><input type="radio" name="name" value="john" /> John</label></div>
+<div><label><input type="radio" name="name" value="paul" /> Paul</label></div>
+<div><label><input type="radio" name="name" value="george" /> George</label></div>
+<div><label><input type="radio" name="name" value="ringo" /> Ringo</label></div>""")
+
+ def test_form_with_noniterable_boundfield(self):
+ # You can iterate over any BoundField, not just those with widget=RadioSelect.
+ class BeatleForm(Form):
+ name = CharField()
+
+ f = BeatleForm(auto_id=False)
+ self.assertEqual('\n'.join(list(f['name'])), u'<input type="text" name="name" />')
+
def test_forms_wit_hmultiple_choice(self):
# MultipleChoiceField is a special case, as its data is required to be a list:
class SongForm(Form):