Ticket #12074: formset-as_p-as_ul-with-tests.patch

File formset-as_p-as_ul-with-tests.patch, 3.1 KB (added by David Novakovic, 14 years ago)
  • django/forms/formsets.py

    diff -r 8c064fcf7778 django/forms/formsets.py
    a b  
    328328        forms = u' '.join([form.as_table() for form in self.forms])
    329329        return mark_safe(u'\n'.join([unicode(self.management_form), forms]))
    330330
     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
    331341def formset_factory(form, formset=BaseFormSet, extra=1, can_order=False,
    332342                    can_delete=False, max_num=None):
    333343    """Return a FormSet for the given form class."""
  • tests/regressiontests/forms/formsets.py

    diff -r 8c064fcf7778 tests/regressiontests/forms/formsets.py
    a b  
    688688<tr><th><label for="id_form-0-name">Name:</label></th><td><input type="text" name="form-0-name" value="Gin Tonic" id="id_form-0-name" /></td></tr>
    689689<tr><th><label for="id_form-1-name">Name:</label></th><td><input type="text" name="form-1-name" id="id_form-1-name" /></td></tr>
    690690
     691>>> print formset.as_table()
     692<input type="hidden" name="form-TOTAL_FORMS" value="2" id="id_form-TOTAL_FORMS" /><input type="hidden" name="form-INITIAL_FORMS" value="1" id="id_form-INITIAL_FORMS" /><input type="hidden" name="form-MAX_NUM_FORMS" value="2" id="id_form-MAX_NUM_FORMS" />
     693<tr><th><label for="id_form-0-name">Name:</label></th><td><input type="text" name="form-0-name" value="Gin Tonic" id="id_form-0-name" /></td></tr> <tr><th><label for="id_form-1-name">Name:</label></th><td><input type="text" name="form-1-name" id="id_form-1-name" /></td></tr>
     694
     695>>> print formset.as_p()
     696<input type="hidden" name="form-TOTAL_FORMS" value="2" id="id_form-TOTAL_FORMS" /><input type="hidden" name="form-INITIAL_FORMS" value="1" id="id_form-INITIAL_FORMS" /><input type="hidden" name="form-MAX_NUM_FORMS" value="2" id="id_form-MAX_NUM_FORMS" />
     697<p><label for="id_form-0-name">Name:</label> <input type="text" name="form-0-name" value="Gin Tonic" id="id_form-0-name" /></p> <p><label for="id_form-1-name">Name:</label> <input type="text" name="form-1-name" id="id_form-1-name" /></p>
     698
     699>>> print formset.as_ul()
     700<input type="hidden" name="form-TOTAL_FORMS" value="2" id="id_form-TOTAL_FORMS" /><input type="hidden" name="form-INITIAL_FORMS" value="1" id="id_form-INITIAL_FORMS" /><input type="hidden" name="form-MAX_NUM_FORMS" value="2" id="id_form-MAX_NUM_FORMS" />
     701<li><label for="id_form-0-name">Name:</label> <input type="text" name="form-0-name" value="Gin Tonic" id="id_form-0-name" /></li> <li><label for="id_form-1-name">Name:</label> <input type="text" name="form-1-name" id="id_form-1-name" /></li>
    691702
    692703# Regression test for #6926 ##################################################
    693704
Back to Top