From fc90c09efdfbc029d43e6d4c0952ed6b49f6f34d Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Wed, 7 Dec 2011 22:31:39 +0000 Subject: 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 --- tests/regressiontests/forms/tests/forms.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'tests') 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):
  • """) + 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'])), """ + + +""") + self.assertEqual('\n'.join(['
    %s
    ' % bf for bf in f['name']]), """
    +
    +
    +
    """) + + 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'') + def test_forms_wit_hmultiple_choice(self): # MultipleChoiceField is a special case, as its data is required to be a list: class SongForm(Form): -- cgit v1.3