1
0
mirror of https://github.com/django/django.git synced 2025-10-24 22:26:08 +00:00

Fixed #11418 -- formset.cleaned_data no longer raises AttributeError when is_valid is True. Thanks mlavin!

This also introduces a slightly backwards-incompatible change in
FormSet's behavior, see the release docs for details.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14667 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Honza Král
2010-11-21 17:27:01 +00:00
parent 752bd8bf75
commit 65b380e74a
4 changed files with 93 additions and 13 deletions

View File

@@ -37,8 +37,8 @@ class BaseFormSet(StrAndUnicode):
self.is_bound = data is not None or files is not None
self.prefix = prefix or self.get_default_prefix()
self.auto_id = auto_id
self.data = data
self.files = files
self.data = data or {}
self.files = files or {}
self.initial = initial
self.error_class = error_class
self._errors = None
@@ -51,7 +51,7 @@ class BaseFormSet(StrAndUnicode):
def _management_form(self):
"""Returns the ManagementForm instance for this FormSet."""
if self.data or self.files:
if self.is_bound:
form = ManagementForm(self.data, auto_id=self.auto_id, prefix=self.prefix)
if not form.is_valid():
raise ValidationError('ManagementForm data is missing or has been tampered with')
@@ -66,7 +66,7 @@ class BaseFormSet(StrAndUnicode):
def total_form_count(self):
"""Returns the total number of forms in this FormSet."""
if self.data or self.files:
if self.is_bound:
return self.management_form.cleaned_data[TOTAL_FORM_COUNT]
else:
initial_forms = self.initial_form_count()
@@ -81,7 +81,7 @@ class BaseFormSet(StrAndUnicode):
def initial_form_count(self):
"""Returns the number of forms that are required in this FormSet."""
if self.data or self.files:
if self.is_bound:
return self.management_form.cleaned_data[INITIAL_FORM_COUNT]
else:
# Use the length of the inital data if it's there, 0 otherwise.
@@ -101,7 +101,7 @@ class BaseFormSet(StrAndUnicode):
Instantiates and returns the i-th form instance in a formset.
"""
defaults = {'auto_id': self.auto_id, 'prefix': self.add_prefix(i)}
if self.data or self.files:
if self.is_bound:
defaults['data'] = self.data
defaults['files'] = self.files
if self.initial:
@@ -133,7 +133,7 @@ class BaseFormSet(StrAndUnicode):
'prefix': self.add_prefix('__prefix__'),
'empty_permitted': True,
}
if self.data or self.files:
if self.is_bound:
defaults['data'] = self.data
defaults['files'] = self.files
defaults.update(kwargs)