Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

newforms-admin: Fixed #6926. Formset management forms now use the pro…

…per prefix. Thanks, msundstr.

git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@7391 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 613c391461cec08786c6ecfdfb287c740d47b1e4 1 parent b2b6fb6
@jkocherhans jkocherhans authored
View
1  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>
View
17 django/newforms/formsets.py
@@ -40,20 +40,21 @@ def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None,
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 = []
View
17 tests/regressiontests/forms/formsets.py
@@ -494,4 +494,21 @@
>>> 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'
+
"""
Please sign in to comment.
Something went wrong with that request. Please try again.