Django

Code

Changeset 4284

Show
Ignore:
Timestamp:
01/04/07 00:25:53 (2 years ago)
Author:
adrian
Message:

newforms: Changed Form so that clean_data only exists if a Form is valid. Thanks for the idea, Honza Kral

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/newforms/forms.py

    r4265 r4284  
    4545        self.auto_id = auto_id 
    4646        self.prefix = prefix 
    47         self.clean_data = None # Stores the data after clean() has been called. 
    4847        self.__errors = None # Stores the errors after clean() has been called. 
    4948 
     
    138137        Cleans all of self.data and populates self.__errors and self.clean_data. 
    139138        """ 
    140         self.clean_data = {} 
    141139        errors = ErrorDict() 
    142140        if self.ignore_errors: # Stop further processing. 
    143141            self.__errors = errors 
    144142            return 
     143        self.clean_data = {} 
    145144        for name, field in self.fields.items(): 
    146145            # value_from_datadict() gets the data from the dictionary. 
     
    161160            errors[NON_FIELD_ERRORS] = e.messages 
    162161        if errors: 
    163             self.clean_data = None 
     162            delattr(self, 'clean_data') 
    164163        self.__errors = errors 
    165164 
  • django/trunk/tests/regressiontests/forms/tests.py

    r4272 r4284  
    15451545>>> p.is_valid() 
    15461546False 
     1547>>> p.clean_data 
     1548Traceback (most recent call last): 
     1549... 
     1550AttributeError: 'birthday' object has no attribute 'clean_data' 
    15471551>>> print p 
    15481552<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> 
     
    15731577>>> p.is_valid() 
    15741578False 
     1579>>> p.clean_data 
     1580Traceback (most recent call last): 
     1581... 
     1582AttributeError: 'birthday' object has no attribute 'clean_data' 
    15751583>>> print p 
    15761584<tr><th><label for="id_first_name">First name:</label></th><td><input type="text" name="first_name" id="id_first_name" /></td></tr> 
     
    16121620  * This field is required. 
    16131621>>> p.clean_data 
    1614 >>> repr(p.clean_data) 
    1615 'None' 
     1622Traceback (most recent call last): 
     1623... 
     1624AttributeError: 'birthday' object has no attribute 'clean_data' 
    16161625>>> p['first_name'].errors 
    16171626[u'This field is required.']