Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

newforms: Changed Form so that clean_data only exists if a Form is va…

…lid. Thanks for the idea, Honza Kral

git-svn-id: http://code.djangoproject.com/svn/django/trunk@4284 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit b1f6b376c0593171f2782472574384b121e65de0 1 parent ddb9b7d
Adrian Holovaty authored January 04, 2007
5  django/newforms/forms.py
@@ -44,7 +44,6 @@ def __init__(self, data=None, auto_id='id_%s', prefix=None):
44 44
         self.data = data or {}
45 45
         self.auto_id = auto_id
46 46
         self.prefix = prefix
47  
-        self.clean_data = None # Stores the data after clean() has been called.
48 47
         self.__errors = None # Stores the errors after clean() has been called.
49 48
 
50 49
     def __unicode__(self):
@@ -137,11 +136,11 @@ def full_clean(self):
137 136
         """
138 137
         Cleans all of self.data and populates self.__errors and self.clean_data.
139 138
         """
140  
-        self.clean_data = {}
141 139
         errors = ErrorDict()
142 140
         if self.ignore_errors: # Stop further processing.
143 141
             self.__errors = errors
144 142
             return
  143
+        self.clean_data = {}
145 144
         for name, field in self.fields.items():
146 145
             # value_from_datadict() gets the data from the dictionary.
147 146
             # Each widget type knows how to retrieve its own data, because some
@@ -160,7 +159,7 @@ def full_clean(self):
160 159
         except ValidationError, e:
161 160
             errors[NON_FIELD_ERRORS] = e.messages
162 161
         if errors:
163  
-            self.clean_data = None
  162
+            delattr(self, 'clean_data')
164 163
         self.__errors = errors
165 164
 
166 165
     def clean(self):
13  tests/regressiontests/forms/tests.py
@@ -1544,6 +1544,10 @@
1544 1544
 {'first_name': [u'This field is required.'], 'last_name': [u'This field is required.'], 'birthday': [u'This field is required.']}
1545 1545
 >>> p.is_valid()
1546 1546
 False
  1547
+>>> p.clean_data
  1548
+Traceback (most recent call last):
  1549
+...
  1550
+AttributeError: 'birthday' object has no attribute 'clean_data'
1547 1551
 >>> print p
1548 1552
 <tr><th><label for="id_first_name">First name:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="first_name" id="id_first_name" /></td></tr>
1549 1553
 <tr><th><label for="id_last_name">Last name:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="last_name" id="id_last_name" /></td></tr>
@@ -1572,6 +1576,10 @@
1572 1576
 {}
1573 1577
 >>> p.is_valid()
1574 1578
 False
  1579
+>>> p.clean_data
  1580
+Traceback (most recent call last):
  1581
+...
  1582
+AttributeError: 'birthday' object has no attribute 'clean_data'
1575 1583
 >>> print p
1576 1584
 <tr><th><label for="id_first_name">First name:</label></th><td><input type="text" name="first_name" id="id_first_name" /></td></tr>
1577 1585
 <tr><th><label for="id_last_name">Last name:</label></th><td><input type="text" name="last_name" id="id_last_name" /></td></tr>
@@ -1611,8 +1619,9 @@
1611 1619
 * birthday
1612 1620
   * This field is required.
1613 1621
 >>> p.clean_data
1614  
->>> repr(p.clean_data)
1615  
-'None'
  1622
+Traceback (most recent call last):
  1623
+...
  1624
+AttributeError: 'birthday' object has no attribute 'clean_data'
1616 1625
 >>> p['first_name'].errors
1617 1626
 [u'This field is required.']
1618 1627
 >>> p['first_name'].errors.as_ul()

0 notes on commit b1f6b37

Please sign in to comment.
Something went wrong with that request. Please try again.