Ticket #12074: formset-as_p-as_ul-with-unittests.patch
File formset-as_p-as_ul-with-unittests.patch, 3.9 KB (added by , 14 years ago) |
---|
-
django/forms/formsets.py
diff -r 8c064fcf7778 django/forms/formsets.py
a b 328 328 forms = u' '.join([form.as_table() for form in self.forms]) 329 329 return mark_safe(u'\n'.join([unicode(self.management_form), forms])) 330 330 331 def as_p(self): 332 "Returns this formset rendered as HTML <p>s." 333 forms = u' '.join([form.as_p() for form in self.forms]) 334 return mark_safe(u'\n'.join([unicode(self.management_form), forms])) 335 336 def as_ul(self): 337 "Returns this formset rendered as HTML <li>s." 338 forms = u' '.join([form.as_ul() for form in self.forms]) 339 return mark_safe(u'\n'.join([unicode(self.management_form), forms])) 340 331 341 def formset_factory(form, formset=BaseFormSet, extra=1, can_order=False, 332 342 can_delete=False, max_num=None): 333 343 """Return a FormSet for the given form class.""" -
tests/regressiontests/forms/formsets.py
diff -r 8c064fcf7778 tests/regressiontests/forms/formsets.py
a b 1 1 # -*- coding: utf-8 -*- 2 from django.test.testcases import TestCase 3 from django.forms.forms import Form 4 from django.forms.fields import CharField, IntegerField 5 from django.forms.formsets import formset_factory 2 6 tests = """ 3 7 # Basic FormSet creation and usage ############################################ 4 8 … … 722 726 <ul class="errorlist"><li>You may only specify a drink once.</li></ul> 723 727 724 728 """ 729 730 data = { 731 'choices-TOTAL_FORMS': '1', # the number of forms rendered 732 'choices-INITIAL_FORMS': '0', # the number of forms with initial data 733 'choices-MAX_NUM_FORMS': '0', # max number of forms 734 'choices-0-choice': 'Calexico', 735 'choices-0-votes': '100', 736 } 737 738 class Choice(Form): 739 choice = CharField() 740 votes = IntegerField() 741 742 ChoiceFormSet = formset_factory(Choice) 743 744 class FormsetAsFooTests(TestCase): 745 def test_as_table(self): 746 formset = ChoiceFormSet(data, auto_id=False, prefix='choices') 747 self.assertEqual(formset.as_table(),"""<input type="hidden" name="choices-TOTAL_FORMS" value="1" /><input type="hidden" name="choices-INITIAL_FORMS" value="0" /><input type="hidden" name="choices-MAX_NUM_FORMS" value="0" /> 748 <tr><th>Choice:</th><td><input type="text" name="choices-0-choice" value="Calexico" /></td></tr> 749 <tr><th>Votes:</th><td><input type="text" name="choices-0-votes" value="100" /></td></tr>""") 750 751 def test_as_p(self): 752 formset = ChoiceFormSet(data, auto_id=False, prefix='choices') 753 self.assertEqual(formset.as_p(),"""<input type="hidden" name="choices-TOTAL_FORMS" value="1" /><input type="hidden" name="choices-INITIAL_FORMS" value="0" /><input type="hidden" name="choices-MAX_NUM_FORMS" value="0" /> 754 <p>Choice: <input type="text" name="choices-0-choice" value="Calexico" /></p> 755 <p>Votes: <input type="text" name="choices-0-votes" value="100" /></p>""") 756 757 def test_as_ul(self): 758 formset = ChoiceFormSet(data, auto_id=False, prefix='choices') 759 self.assertEqual(formset.as_ul(),"""<input type="hidden" name="choices-TOTAL_FORMS" value="1" /><input type="hidden" name="choices-INITIAL_FORMS" value="0" /><input type="hidden" name="choices-MAX_NUM_FORMS" value="0" /> 760 <li>Choice: <input type="text" name="choices-0-choice" value="Calexico" /></li> 761 <li>Votes: <input type="text" name="choices-0-votes" value="100" /></li>""") 762 -
tests/regressiontests/forms/tests.py
diff -r 8c064fcf7778 tests/regressiontests/forms/tests.py
a b 37 37 from formsets import tests as formset_tests 38 38 from media import media_tests 39 39 40 41 from formsets import FormsetAsFooTests 40 42 from fields import FieldsTests 41 43 from validators import TestFieldWithValidators 42 44 from widgets import WidgetTests