Fixed #15349 - Bound FormSet produces bound empty_form
Thanks to hidde-jan for the report and patch. git-svn-id: http://code.djangoproject.com/svn/django/trunk@15614 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
13f9fd38dc
commit
c411377bd5
|
@ -144,9 +144,6 @@ class BaseFormSet(StrAndUnicode):
|
||||||
'prefix': self.add_prefix('__prefix__'),
|
'prefix': self.add_prefix('__prefix__'),
|
||||||
'empty_permitted': True,
|
'empty_permitted': True,
|
||||||
}
|
}
|
||||||
if self.is_bound:
|
|
||||||
defaults['data'] = self.data
|
|
||||||
defaults['files'] = self.files
|
|
||||||
defaults.update(kwargs)
|
defaults.update(kwargs)
|
||||||
form = self.form(**defaults)
|
form = self.form(**defaults)
|
||||||
self.add_fields(form, None)
|
self.add_fields(form, None)
|
||||||
|
|
|
@ -878,6 +878,28 @@ class TestIsBoundBehavior(TestCase):
|
||||||
self.assertFalse(formset.is_valid())
|
self.assertFalse(formset.is_valid())
|
||||||
self.assertEquals([{}, {'pub_date': [u'This field is required.']}], formset.errors)
|
self.assertEquals([{}, {'pub_date': [u'This field is required.']}], formset.errors)
|
||||||
|
|
||||||
|
def test_empty_forms_are_unbound(self):
|
||||||
|
data = {
|
||||||
|
'form-TOTAL_FORMS': u'1',
|
||||||
|
'form-INITIAL_FORMS': u'0',
|
||||||
|
'form-0-title': u'Test',
|
||||||
|
'form-0-pub_date': u'1904-06-16',
|
||||||
|
}
|
||||||
|
unbound_formset = ArticleFormSet()
|
||||||
|
bound_formset = ArticleFormSet(data)
|
||||||
|
|
||||||
|
empty_forms = []
|
||||||
|
|
||||||
|
empty_forms.append(unbound_formset.empty_form)
|
||||||
|
empty_forms.append(bound_formset.empty_form)
|
||||||
|
|
||||||
|
# Empty forms should be unbound
|
||||||
|
self.assertFalse(empty_forms[0].is_bound)
|
||||||
|
self.assertFalse(empty_forms[1].is_bound)
|
||||||
|
|
||||||
|
# The empty forms should be equal.
|
||||||
|
self.assertEqual(empty_forms[0].as_p(), empty_forms[1].as_p())
|
||||||
|
|
||||||
class TestEmptyFormSet(TestCase):
|
class TestEmptyFormSet(TestCase):
|
||||||
"Test that an empty formset still calls clean()"
|
"Test that an empty formset still calls clean()"
|
||||||
def test_empty_formset_is_valid(self):
|
def test_empty_formset_is_valid(self):
|
||||||
|
|
Loading…
Reference in New Issue