Index: django/newforms/forms.py =================================================================== --- django/newforms/forms.py (revision 6822) +++ django/newforms/forms.py (working copy) @@ -195,8 +195,6 @@ self.cleaned_data = self.clean() except ValidationError, e: self._errors[NON_FIELD_ERRORS] = e.messages - if self._errors: - delattr(self, 'cleaned_data') def clean(self): """ @@ -290,8 +288,13 @@ def _data(self): """ Returns the data for this BoundField, or None if it wasn't given. + If the data has been cleaned, that value is used; otherwise, the value + is provided by value_from_datadict. """ - return self.field.widget.value_from_datadict(self.form.data, self.form.files, self.html_name) + if hasattr(self.form, 'cleaned_data') and self.name in self.form.cleaned_data: + return self.form.cleaned_data[self.name] + else: + return self.field.widget.value_from_datadict(self.form.data, self.form.files, self.html_name) data = property(_data) def label_tag(self, contents=None, attrs=None): Index: tests/modeltests/model_forms/models.py =================================================================== --- tests/modeltests/model_forms/models.py (revision 6822) +++ tests/modeltests/model_forms/models.py (working copy) @@ -163,9 +163,7 @@ >>> f.errors {'name': [u'This field is required.'], 'slug': [u'This field is required.']} >>> f.cleaned_data -Traceback (most recent call last): -... -AttributeError: 'CategoryForm' object has no attribute 'cleaned_data' +{'url': u'foo'} >>> f.save() Traceback (most recent call last): ... Index: tests/regressiontests/forms/extra.py =================================================================== --- tests/regressiontests/forms/extra.py (revision 6822) +++ tests/regressiontests/forms/extra.py (working copy) @@ -159,7 +159,7 @@ rendering as well. >>> print a['mydate'].as_hidden() - + >>> b=GetDate({'mydate':'2008-4-1'}) >>> print b.is_valid() True Index: tests/regressiontests/forms/forms.py =================================================================== --- tests/regressiontests/forms/forms.py (revision 6822) +++ tests/regressiontests/forms/forms.py (working copy) @@ -43,7 +43,7 @@ >>> print p['last_name'] >>> print p['birthday'] - + >>> print p['nonexistentfield'] Traceback (most recent call last): ... @@ -53,16 +53,16 @@ ... print boundfield - + >>> for boundfield in p: ... print boundfield.label, boundfield.data First name John Last name Lennon -Birthday 1940-10-9 +Birthday 1940-10-09 >>> print p
\n
\n
' +u'
\n
\n
' >>> p = Person({'last_name': u'Lennon'}) >>> p.errors @@ -149,9 +147,7 @@ * birthday * This field is required. >>> p.cleaned_data -Traceback (most recent call last): -... -AttributeError: 'Person' object has no attribute 'cleaned_data' +{'last_name': u'Lennon'} >>> p['first_name'].errors [u'This field is required.'] >>> p['first_name'].errors.as_ul() @@ -802,17 +798,17 @@
First name:
Last name:
-Birthday:
+Birthday:
A corner case: It's possible for a form to have only HiddenInputs. >>> class TestForm(Form): @@ -1247,13 +1243,13 @@ >>> print p.as_ul()