1
0
mirror of https://github.com/django/django.git synced 2025-07-04 09:49:12 +00:00

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
This commit is contained in:
Joseph Kocherhans 2008-03-30 23:54:55 +00:00
parent b2b6fb6b07
commit 613c391461
3 changed files with 27 additions and 8 deletions

View File

@ -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 File

@ -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 = []

View File

@ -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'
"""