Ticket #19545: 0001-Fixed-19545-Make-sure-formsets-with-no-extra-forms-p.patch

File 0001-Fixed-19545-Make-sure-formsets-with-no-extra-forms-p.patch, 2.2 KB (added by charettes, 2 years ago)
  • django/forms/formsets.py

    From 0d7ea17c14dacf1c87072e1d082a66f37b1badf9 Mon Sep 17 00:00:00 2001
    From: Simon Charette <charette.s@gmail.com>
    Date: Tue, 1 Jan 2013 05:33:52 -0500
    Subject: [PATCH] Fixed #19545 -- Make sure formsets with no extra forms
     provide the correct medias
    
    ---
     django/forms/formsets.py                      |    2 +-
     tests/regressiontests/forms/tests/formsets.py |    9 ++++++++-
     2 files changed, 9 insertions(+), 2 deletions(-)
    
    diff --git a/django/forms/formsets.py b/django/forms/formsets.py
    index 3893cc5..a84d3bc 100644
    a b class BaseFormSet(object): 
    344344        if self.forms:
    345345            return self.forms[0].media
    346346        else:
    347             return Media()
     347            return self.empty_form.media
    348348
    349349    def as_table(self):
    350350        "Returns this formset rendered as HTML <tr>s -- excluding the <table></table>."
  • tests/regressiontests/forms/tests/formsets.py

    diff --git a/tests/regressiontests/forms/tests/formsets.py b/tests/regressiontests/forms/tests/formsets.py
    index bf893c4..0bee972 100644
    a b class TestIsBoundBehavior(TestCase): 
    974974        self.assertHTMLEqual(empty_forms[0].as_p(), empty_forms[1].as_p())
    975975
    976976class TestEmptyFormSet(TestCase):
    977     "Test that an empty formset still calls clean()"
    978977    def test_empty_formset_is_valid(self):
     978        """Test that an empty formset still calls clean()"""
    979979        EmptyFsetWontValidateFormset = formset_factory(FavoriteDrinkForm, extra=0, formset=EmptyFsetWontValidate)
    980980        formset = EmptyFsetWontValidateFormset(data={'form-INITIAL_FORMS':'0', 'form-TOTAL_FORMS':'0'},prefix="form")
    981981        formset2 = EmptyFsetWontValidateFormset(data={'form-INITIAL_FORMS':'0', 'form-TOTAL_FORMS':'1', 'form-0-name':'bah' },prefix="form")
    982982        self.assertFalse(formset.is_valid())
    983983        self.assertFalse(formset2.is_valid())
    984984
     985    def test_empty_formset_media(self):
     986        """Make sure media is available on empty formset, refs #19545"""
     987        class MediaForm(Form):
     988            class Media:
     989                js = ('some-file.js',)
     990        self.assertIn('some-file.js', str(formset_factory(MediaForm, extra=0)().media))
     991
Back to Top