1
0
mirror of https://github.com/django/django.git synced 2025-10-26 15:16:09 +00:00

Fixed #3787, #3788 -- Corrected check for IndexError on MultiValueField, and fixed the value_from_datadict method for MultiWidgets to handle Multiwidgets containing Multiwidgets. Also added a testcase walking through the use of MultiWidget/MultiValueField. Thanks to Max Derkachev for reporting these issues and providing fixes.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@5088 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Russell Keith-Magee
2007-04-26 12:46:04 +00:00
parent ed60b8645f
commit b24c860fa2
3 changed files with 91 additions and 2 deletions

View File

@@ -457,7 +457,7 @@ class MultiValueField(Field):
for i, field in enumerate(self.fields):
try:
field_value = value[i]
except KeyError:
except IndexError:
field_value = None
if self.required and field_value in EMPTY_VALUES:
raise ValidationError(gettext(u'This field is required.'))

View File

@@ -347,7 +347,7 @@ class MultiWidget(Widget):
id_for_label = classmethod(id_for_label)
def value_from_datadict(self, data, name):
return [data.get(name + '_%s' % i) for i in range(len(self.widgets))]
return [widget.value_from_datadict(data, name + '_%s' % i) for i, widget in enumerate(self.widgets)]
def format_output(self, rendered_widgets):
return u''.join(rendered_widgets)