Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[1.2.X] Fixed #15349 - Bound FormSet produces bound empty_form

Thanks to hidde-jan for the report and patch.

Backport of [15614] from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@15615 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit e63db6597c89526ce90f83e3327c44c83f095eae 1 parent c326ec4
@spookylukey spookylukey authored
View
3  django/forms/formsets.py
@@ -133,9 +133,6 @@ def _get_empty_form(self, **kwargs):
'prefix': self.add_prefix('__prefix__'),
'empty_permitted': True,
}
- if self.data or self.files:
- defaults['data'] = self.data
- defaults['files'] = self.files
defaults.update(kwargs)
form = self.form(**defaults)
self.add_fields(form, None)
View
53 tests/regressiontests/forms/tests/formsets.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
from unittest import TestCase
-from django.forms import Form, CharField, IntegerField, ValidationError
+from django.forms import Form, CharField, IntegerField, ValidationError, DateField
from django.forms.formsets import formset_factory, BaseFormSet
@@ -41,6 +41,13 @@ def clean(self):
formset=BaseFavoriteDrinksFormSet, extra=3)
+class ArticleForm(Form):
+ title = CharField()
+ pub_date = DateField()
+
+ArticleFormSet = formset_factory(ArticleForm)
+
+
class FormsFormsetTestCase(TestCase):
def test_basic_formset(self):
# A FormSet constructor takes the same arguments as Form. Let's create a FormSet
@@ -767,6 +774,50 @@ def test_regression_12878(self):
self.assertFalse(formset.is_valid())
self.assertEqual(formset.non_form_errors(), [u'You may only specify a drink once.'])
+ 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())
+
+ 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):
"Test that an empty formset still calls clean()"
def test_empty_formset_is_valid(self):
Please sign in to comment.
Something went wrong with that request. Please try again.