| | 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 | |