summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Kocherhans <joseph@jkocherhans.com>2008-03-30 23:54:55 +0000
committerJoseph Kocherhans <joseph@jkocherhans.com>2008-03-30 23:54:55 +0000
commit613c391461cec08786c6ecfdfb287c740d47b1e4 (patch)
tree2b155463d88d7c2b63406c4c950889cc5f992920
parentb2b6fb6b0704b8c788479c92f34bdababcb25054 (diff)
newforms-admin: Fixed #6926. Formset management forms now use the proper prefix. Thanks, msundstr.
git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@7391 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--AUTHORS1
-rw-r--r--django/newforms/formsets.py17
-rw-r--r--tests/regressiontests/forms/formsets.py17
3 files changed, 27 insertions, 8 deletions
diff --git a/AUTHORS b/AUTHORS
index 58d2918c3b..19eeb5ea3c 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -263,6 +263,7 @@ answer newbie questions, and generally made Django that much better:
Eric Moritz <http://eric.themoritzfamily.com/>
mrmachine <real.human@mrmachine.net>
Robin Munn <http://www.geekforgod.com/>
+ msundstr
Robert Myers <myer0052@gmail.com>
Nebojša Dorđević
Doug Napoleone <doug@dougma.com>
diff --git a/django/newforms/formsets.py b/django/newforms/formsets.py
index a11aed8221..6cd7b54993 100644
--- a/django/newforms/formsets.py
+++ b/django/newforms/formsets.py
@@ -40,20 +40,21 @@ class BaseFormSet(StrAndUnicode):
self._non_form_errors = None
# initialization is different depending on whether we recieved data, initial, or nothing
if data or files:
- self.management_form = ManagementForm(data, files, auto_id=self.auto_id, prefix=self.prefix)
+ self.management_form = ManagementForm(data, auto_id=self.auto_id, prefix=self.prefix)
if self.management_form.is_valid():
self._total_form_count = self.management_form.cleaned_data[TOTAL_FORM_COUNT]
self._initial_form_count = self.management_form.cleaned_data[INITIAL_FORM_COUNT]
else:
raise ValidationError('ManagementForm data is missing or has been tampered with')
- elif initial:
- self._initial_form_count = len(initial)
- self._total_form_count = self._initial_form_count + self.extra
else:
- self._initial_form_count = 0
- self._total_form_count = self.extra
- initial = {TOTAL_FORM_COUNT: self._total_form_count, INITIAL_FORM_COUNT: self._initial_form_count}
- self.management_form = ManagementForm(initial=initial, auto_id=auto_id, prefix=prefix)
+ if initial:
+ self._initial_form_count = len(initial)
+ self._total_form_count = self._initial_form_count + self.extra
+ else:
+ self._initial_form_count = 0
+ self._total_form_count = self.extra
+ initial = {TOTAL_FORM_COUNT: self._total_form_count, INITIAL_FORM_COUNT: self._initial_form_count}
+ self.management_form = ManagementForm(initial=initial, auto_id=self.auto_id, prefix=self.prefix)
# instantiate all the forms and put them in self.forms
self.forms = []
diff --git a/tests/regressiontests/forms/formsets.py b/tests/regressiontests/forms/formsets.py
index fea8f057da..a0e0215660 100644
--- a/tests/regressiontests/forms/formsets.py
+++ b/tests/regressiontests/forms/formsets.py
@@ -494,4 +494,21 @@ True
>>> for error in formset.non_form_errors():
... print error
+
+# Regression test for #6926 ##################################################
+
+Make sure the management form has the correct prefix.
+
+>>> formset = FavoriteDrinksFormSet()
+>>> formset.management_form.prefix
+'form'
+
+>>> formset = FavoriteDrinksFormSet(data={})
+>>> formset.management_form.prefix
+'form'
+
+>>> formset = FavoriteDrinksFormSet(initial={})
+>>> formset.management_form.prefix
+'form'
+
"""