Django

Code

Changeset 5241

Show
Ignore:
Timestamp:
05/14/07 14:42:13 (2 years ago)
Author:
mtredinnick
Message:

unicode: Merged from trunk to [5237].

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/unicode

    • Property svnmerge-integrated changed from /django/trunk:1-5223 to /django/trunk:1-5240
  • django/branches/unicode/AUTHORS

    r5227 r5241  
    8787    deric@monowerks.com 
    8888    Max Derkachev <mderk@yandex.ru> 
     89    Jordan Dimov <s3x3y1@gmail.com> 
    8990    dne@mayonnaise.net 
    9091    Maximillian Dornseif <md@hudora.de> 
  • django/branches/unicode/django/conf/global_settings.py

    r5151 r5241  
    3939    ('ar', gettext_noop('Arabic')), 
    4040    ('bn', gettext_noop('Bengali')), 
     41    ('bg', gettext_noop('Bulgarian')), 
    4142    ('ca', gettext_noop('Catalan')), 
    4243    ('cs', gettext_noop('Czech')), 
  • django/branches/unicode/django/contrib/formtools/preview.py

    r4265 r5241  
    2525Subclass FormPreview and define a done() method: 
    2626 
    27     def done(self, request, clean_data): 
     27    def done(self, request, cleaned_data): 
    2828        # ... 
    2929 
     
    114114            if self.security_hash(request, f) != request.POST.get(self.unused_name('hash')): 
    115115                return self.failed_hash(request) # Security hash failed. 
    116             return self.done(request, f.clean_data) 
     116            return self.done(request, f.cleaned_data) 
    117117        else: 
    118118            return render_to_response(self.form_template, 
     
    161161    # METHODS SUBCLASSES MUST OVERRIDE ######################################## 
    162162 
    163     def done(self, request, clean_data): 
    164         "Does something with the clean_data and returns an HttpResponseRedirect." 
     163    def done(self, request, cleaned_data): 
     164        """ 
     165        Does something with the cleaned_data and returns an 
     166        HttpResponseRedirect. 
     167        """ 
    165168        raise NotImplementedError('You must define a done() method on your %s subclass.' % self.__class__.__name__) 
  • django/branches/unicode/django/core/management.py

    r5185 r5241  
    14051405                        print "No %s fixture '%s' in %s." % \ 
    14061406                            (format, fixture_name, humanize(fixture_dir)) 
     1407                             
     1408    if count[0] > 0: 
     1409        sequence_sql = backend.get_sql_sequence_reset(style, models) 
     1410        if sequence_sql: 
     1411            if verbosity > 1: 
     1412                print "Resetting sequences" 
     1413            for line in sequence_sql: 
     1414                cursor.execute(line) 
     1415             
     1416    transaction.commit() 
     1417    transaction.leave_transaction_management() 
     1418     
    14071419    if count[0] == 0: 
    14081420        if verbosity > 0: 
     
    14111423        if verbosity > 0: 
    14121424            print "Installed %d object(s) from %d fixture(s)" % tuple(count) 
    1413         sequence_sql = backend.get_sql_sequence_reset(style, models) 
    1414         if sequence_sql: 
    1415             if verbosity > 1: 
    1416                 print "Resetting sequences" 
    1417             for line in sequence_sql: 
    1418                 cursor.execute(line) 
    1419     transaction.commit() 
    1420     transaction.leave_transaction_management() 
    14211425 
    14221426load_data.help_doc = 'Installs the named fixture(s) in the database' 
  • django/branches/unicode/django/core/serializers/python.py

    r4718 r5241  
    3838        related = getattr(obj, field.name) 
    3939        if related is not None: 
    40             related = related._get_pk_val(
     40            related = getattr(related, field.rel.field_name
    4141        self._current[field.name] = related 
    4242     
     
    8181            # Handle FK fields 
    8282            elif field.rel and isinstance(field.rel, models.ManyToOneRel): 
    83                 data[field.attname] = field.rel.to._meta.pk.to_python(field_value) 
     83                if field_value: 
     84                    data[field.attname] = field.rel.to._meta.get_field(field.rel.field_name).to_python(field_value) 
     85                else: 
     86                    data[field.attname] = None 
    8487                     
    8588            # Handle all other fields 
  • django/branches/unicode/django/core/serializers/xml_serializer.py

    r4733 r5241  
    8383        related = getattr(obj, field.name) 
    8484        if related is not None: 
    85             self.xml.characters(str(related._get_pk_val())) 
     85            self.xml.characters(str(getattr(related, field.rel.field_name))) 
    8686        else: 
    8787            self.xml.addQuickElement("None") 
     
    182182            return None 
    183183        else: 
    184             return field.rel.to._meta.pk.to_python( 
     184            return field.rel.to._meta.get_field(field.rel.field_name).to_python( 
    185185                       getInnerText(node).strip().encode(self.encoding)) 
    186186         
  • django/branches/unicode/django/newforms/forms.py

    r5236 r5241  
    170170    def full_clean(self): 
    171171        """ 
    172         Cleans all of self.data and populates self.__errors and self.clean_data. 
     172        Cleans all of self.data and populates self.__errors and self.cleaned_data. 
    173173        """ 
    174174        errors = ErrorDict() 
     
    176176            self.__errors = errors 
    177177            return 
    178         self.clean_data = {} 
     178        self.cleaned_data = {} 
    179179        for name, field in self.fields.items(): 
    180180            # value_from_datadict() gets the data from the dictionary. 
     
    184184            try: 
    185185                value = field.clean(value) 
    186                 self.clean_data[name] = value 
     186                self.cleaned_data[name] = value 
    187187                if hasattr(self, 'clean_%s' % name): 
    188188                    value = getattr(self, 'clean_%s' % name)() 
    189                 self.clean_data[name] = value 
     189                self.cleaned_data[name] = value 
    190190            except ValidationError, e: 
    191191                errors[name] = e.messages 
    192192        try: 
    193             self.clean_data = self.clean() 
     193            self.cleaned_data = self.clean() 
    194194        except ValidationError, e: 
    195195            errors[NON_FIELD_ERRORS] = e.messages 
    196196        if errors: 
    197             delattr(self, 'clean_data') 
     197            delattr(self, 'cleaned_data') 
    198198        self.__errors = errors 
    199199 
     
    205205        association with the field named '__all__'. 
    206206        """ 
    207         return self.clean_data 
     207        return self.cleaned_data 
    208208 
    209209class Form(BaseForm): 
  • django/branches/unicode/django/newforms/models.py

    r5236 r5241  
    1616def save_instance(form, instance, fields=None, fail_message='saved', commit=True): 
    1717    """ 
    18     Saves bound Form ``form``'s clean_data into model instance ``instance``. 
     18    Saves bound Form ``form``'s cleaned_data into model instance ``instance``. 
    1919 
    2020    Assumes ``form`` has a field for every non-AutoField database field in 
     
    2626    if form.errors: 
    2727        raise ValueError("The %s could not be %s because the data didn't validate." % (opts.object_name, fail_message)) 
    28     clean_data = form.clean_data 
     28    cleaned_data = form.cleaned_data 
    2929    for f in opts.fields: 
    30         if not f.editable or isinstance(f, models.AutoField) or not f.name in clean_data: 
     30        if not f.editable or isinstance(f, models.AutoField) or not f.name in cleaned_data: 
    3131            continue 
    3232        if fields and f.name not in fields: 
    3333            continue 
    34         setattr(instance, f.name, clean_data[f.name]) 
     34        setattr(instance, f.name, cleaned_data[f.name]) 
    3535    if commit: 
    3636        instance.save() 
     
    3838            if fields and f.name not in fields: 
    3939                continue 
    40             if f.name in clean_data: 
    41                 setattr(instance, f.attname, clean_data[f.name]) 
     40            if f.name in cleaned_data: 
     41                setattr(instance, f.attname, cleaned_data[f.name]) 
    4242    # GOTCHA: If many-to-many data is given and commit=False, the many-to-many 
    4343    # data will be lost. This happens because a many-to-many options cannot be 
  • django/branches/unicode/django/test/testcases.py

    r5224 r5241  
    6363        """ 
    6464        self.assertEqual(response.status_code, status_code,  
    65             "Response didn't redirect: Reponse code was %d (expected %d)" %  
     65            "Response didn't redirect as expected: Reponse code was %d (expected %d)" %  
    6666                (response.status_code, status_code)) 
    6767        scheme, netloc, path, params, query, fragment = urlparse(response['Location']) 
     
    7171        self.assertEqual(redirect_response.status_code, target_status_code,  
    7272            "Couldn't retrieve redirection page '%s': response code was %d (expected %d)" %  
    73                 (path, response.status_code, status_code)) 
     73                (path, redirect_response.status_code, target_status_code)) 
    7474     
    7575    def assertContains(self, response, text, count=1, status_code=200): 
  • django/branches/unicode/docs/newforms.txt

    r5224 r5241  
    231231 
    232232Once you've created a ``Form`` instance with a set of data and validated it, 
    233 you can access the clean data via the ``clean_data`` attribute of the ``Form`` 
     233you can access the clean data via the ``cleaned_data`` attribute of the ``Form`` 
    234234object:: 
    235235 
     
    241241    >>> f.is_valid() 
    242242    True 
    243     >>> f.clean_data 
     243    >>> f.cleaned_data 
    244244    {'cc_myself': True, 'message': u'Hi there', 'sender': u'foo@example.com', 'subject': u'hello'} 
    245245 
     
    249249 
    250250If your data does *not* validate, your ``Form`` instance will not have a 
    251 ``clean_data`` attribute:: 
     251``cleaned_data`` attribute:: 
    252252 
    253253    >>> data = {'subject': '', 
     
    258258    >>> f.is_valid() 
    259259    False 
    260     >>> f.clean_data 
     260    >>> f.cleaned_data 
    261261    Traceback (most recent call last): 
    262262    ... 
    263     AttributeError: 'ContactForm' object has no attribute 'clean_data' 
    264  
    265 ``clean_data`` will always *only* contain a key for fields defined in the 
     263    AttributeError: 'ContactForm' object has no attribute 'cleaned_data' 
     264 
     265``cleaned_data`` will always *only* contain a key for fields defined in the 
    266266``Form``, even if you pass extra data when you define the ``Form``. In this 
    267267example, we pass a bunch of extra fields to the ``ContactForm`` constructor, 
    268 but ``clean_data`` contains only the form's fields:: 
     268but ``cleaned_data`` contains only the form's fields:: 
    269269 
    270270    >>> data = {'subject': 'hello', 
     
    278278    >>> f.is_valid() 
    279279    True 
    280     >>> f.clean_data # Doesn't contain extra_field_1, etc. 
     280    >>> f.cleaned_data # Doesn't contain extra_field_1, etc. 
    281281    {'cc_myself': True, 'message': u'Hi there', 'sender': u'foo@example.com', 'subject': u'hello'} 
    282282 
    283 ``clean_data`` will include a key and value for *all* fields defined in the 
     283``cleaned_data`` will include a key and value for *all* fields defined in the 
    284284``Form``, even if the data didn't include a value for fields that are not 
    285285required. In this example, the data dictionary doesn't include a value for the 
    286 ``nick_name`` field, but ``clean_data`` includes it, with an empty value:: 
     286``nick_name`` field, but ``cleaned_data`` includes it, with an empty value:: 
    287287 
    288288    >>> class OptionalPersonForm(Form): 
     
    294294    >>> f.is_valid() 
    295295    True 
    296     >>> f.clean_data 
     296    >>> f.cleaned_data 
    297297    {'nick_name': u'', 'first_name': u'John', 'last_name': u'Lennon'} 
    298298 
    299 In this above example, the ``clean_data`` value for ``nick_name`` is set to an 
     299In this above example, the ``cleaned_data`` value for ``nick_name`` is set to an 
    300300empty string, because ``nick_name`` is ``CharField``, and ``CharField``\s treat 
    301301empty values as an empty string. Each field type knows what its "blank" value 
     
    309309 
    310310    >>> f = ContactForm() 
    311     >>> f.clean_data 
     311    >>> f.cleaned_data 
    312312    Traceback (most recent call last): 
    313313    ... 
    314     AttributeError: 'ContactForm' object has no attribute 'clean_data' 
     314    AttributeError: 'ContactForm' object has no attribute 'cleaned_data' 
    315315 
    316316Outputting forms as HTML 
  • django/branches/unicode/tests/modeltests/model_forms/models.py

    r5214 r5241  
    1919 
    2020The function django.newforms.save_instance() takes a bound form instance and a 
    21 model instance and saves the form's clean_data into the instance. It also takes 
     21model instance and saves the form's cleaned_data into the instance. It also takes 
    2222a commit=True parameter. 
    2323""" 
     
    9595>>> f.is_valid() 
    9696True 
    97 >>> f.clean_data 
     97>>> f.cleaned_data 
    9898{'url': u'entertainment', 'name': u'Entertainment'} 
    9999>>> obj = f.save() 
     
    106106>>> f.is_valid() 
    107107True 
    108 >>> f.clean_data 
     108>>> f.cleaned_data 
    109109{'url': u'test', 'name': u"It's a test"} 
    110110>>> obj = f.save() 
     
    120120>>> f.is_valid() 
    121121True 
    122 >>> f.clean_data 
     122>>> f.cleaned_data 
    123123{'url': u'third', 'name': u'Third test'} 
    124124>>> obj = f.save(commit=False) 
     
    135135>>> f.errors 
    136136{'name': [u'This field is required.']} 
    137 >>> f.clean_data 
    138 Traceback (most recent call last): 
    139 ... 
    140 AttributeError: 'CategoryForm' object has no attribute 'clean_data' 
     137>>> f.cleaned_data 
     138Traceback (most recent call last): 
     139... 
     140AttributeError: 'CategoryForm' object has no attribute 'cleaned_data' 
    141141>>> f.save() 
    142142Traceback (most recent call last): 
     
    525525>>> f.is_valid() 
    526526True 
    527 >>> f.clean_data 
     527>>> f.cleaned_data 
    528528{'phone': u'312-555-1212', 'description': u'Assistance'} 
    529529"""} 
  • django/branches/unicode/tests/regressiontests/forms/regressions.py

    r5238 r5241  
    5353>>> f.clean('\xd1\x88\xd1\x82.') 
    5454u'\u0448\u0442.' 
     55 
     56####################### 
     57# Miscellaneous Tests # 
     58####################### 
     59 
     60There once was a problem with Form fields called "data". Let's make sure that 
     61doesn't come back. 
     62>>> class DataForm(Form): 
     63...     data = CharField(max_length=10) 
     64>>> f = DataForm({'data': 'xyzzy'}) 
     65>>> f.is_valid() 
     66True 
     67>>> f.cleaned_data 
     68{'data': u'xyzzy'} 
    5569""" 
  • django/branches/unicode/tests/regressiontests/forms/tests.py

    r5224 r5241  
    17751775>>> p.errors.as_text() 
    17761776u'' 
    1777 >>> p.clean_data 
     1777>>> p.cleaned_data 
    17781778{'first_name': u'John', 'last_name': u'Lennon', 'birthday': datetime.date(1940, 10, 9)} 
    17791779>>> print p['first_name'] 
     
    18111811>>> p.is_valid() 
    18121812False 
    1813 >>> p.clean_data 
    1814 Traceback (most recent call last): 
    1815 ... 
    1816 AttributeError: 'Person' object has no attribute 'clean_data' 
     1813>>> p.cleaned_data 
     1814Traceback (most recent call last): 
     1815... 
     1816AttributeError: 'Person' object has no attribute 'cleaned_data' 
    18171817>>> print p 
    18181818<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> 
     
    18451845>>> p.is_valid() 
    18461846False 
    1847 >>> p.clean_data 
    1848 Traceback (most recent call last): 
    1849 ... 
    1850 AttributeError: 'Person' object has no attribute 'clean_data' 
     1847>>> p.cleaned_data 
     1848Traceback (most recent call last): 
     1849... 
     1850AttributeError: 'Person' object has no attribute 'cleaned_data' 
    18511851>>> print p 
    18521852<tr><th><label for="id_first_name">First name:</label></th><td><input type="text" name="first_name" id="id_first_name" /></td></tr> 
     
    18871887* birthday 
    18881888  * This field is required. 
    1889 >>> p.clean_data 
    1890 Traceback (most recent call last): 
    1891 ... 
    1892 AttributeError: 'Person' object has no attribute 'clean_data' 
     1889>>> p.cleaned_data 
     1890Traceback (most recent call last): 
     1891... 
     1892AttributeError: 'Person' object has no attribute 'cleaned_data' 
    18931893>>> p['first_name'].errors 
    18941894[u'This field is required.'] 
     
    19061906<input type="text" name="birthday" id="id_birthday" /> 
    19071907 
    1908 clean_data will always *only* contain a key for fields defined in the 
     1908cleaned_data will always *only* contain a key for fields defined in the 
    19091909Form, even if you pass extra data when you define the Form. In this 
    19101910example, we pass a bunch of extra fields to the form constructor, 
    1911 but clean_data contains only the form's fields. 
     1911but cleaned_data contains only the form's fields. 
    19121912>>> data = {'first_name': u'John', 'last_name': u'Lennon', 'birthday': u'1940-10-9', 'extra1': 'hello', 'extra2': 'hello'} 
    19131913>>> p = Person(data) 
    19141914>>> p.is_valid() 
    19151915True 
    1916 >>> p.clean_data 
     1916>>> p.cleaned_data 
    19171917{'first_name': u'John', 'last_name': u'Lennon', 'birthday': datetime.date(1940, 10, 9)} 
    19181918 
    1919 clean_data will include a key and value for *all* fields defined in the Form, 
     1919cleaned_data will include a key and value for *all* fields defined in the Form, 
    19201920even if the Form's data didn't include a value for fields that are not 
    19211921required. In this example, the data dictionary doesn't include a value for the 
    1922 "nick_name" field, but clean_data includes it. For CharFields, it's set to the 
     1922"nick_name" field, but cleaned_data includes it. For CharFields, it's set to the 
    19231923empty string. 
    19241924>>> class OptionalPersonForm(Form): 
     
    19301930>>> f.is_valid() 
    19311931True 
    1932 >>> f.clean_data 
     1932>>> f.cleaned_data 
    19331933{'nick_name': u'', 'first_name': u'John', 'last_name': u'Lennon'} 
    19341934 
     
    19421942>>> f.is_valid() 
    19431943True 
    1944 >>> f.clean_data 
     1944>>> f.cleaned_data 
    19451945{'birth_date': None, 'first_name': u'John', 'last_name': u'Lennon'} 
    19461946 
     
    22932293>>> f.errors 
    22942294{} 
    2295 >>> f.clean_data 
     2295>>> f.cleaned_data 
    22962296{'composers': [u'J'], 'name': u'Yesterday'} 
    22972297>>> f = SongForm({'name': 'Yesterday', 'composers': ['J', 'P']}, auto_id=False) 
    22982298>>> f.errors 
    22992299{} 
    2300 >>> f.clean_data 
     2300>>> f.cleaned_data 
    23012301{'composers': [u'J', u'P'], 'name': u'Yesterday'} 
    23022302 
     
    23052305...     special_name = CharField() 
    23062306...     def clean_special_name(self): 
    2307 ...         raise ValidationError("Something's wrong with '%s'" % self.clean_data['special_name']) 
     2307...         raise ValidationError("Something's wrong with '%s'" % self.cleaned_data['special_name']) 
    23082308 
    23092309>>> f = EscapingForm({'special_name': "Nothing to escape"}, auto_id=False) 
     
    23202320clean_XXX() method on the Form, where XXX is the field name. As in 
    23212321Field.clean(), the clean_XXX() method should return the cleaned value. In the 
    2322 clean_XXX() method, you have access to self.clean_data, which is a dictionary 
     2322clean_XXX() method, you have access to self.cleaned_data, which is a dictionary 
    23232323of all the data that has been cleaned *so far*, in order by the fields, 
    23242324including the current field (e.g., the field XXX if you're in clean_XXX()). 
     
    23282328...    password2 = CharField(widget=PasswordInput) 
    23292329...    def clean_password2(self): 
    2330 ...        if self.clean_data.get('password1') and self.clean_data.get('password2') and self.clean_data['password1'] != self.clean_data['password2']: 
     2330...        if self.cleaned_data.get('password1') and self.cleaned_data.get('password2') and self.cleaned_data['password1'] != self.cleaned_data['password2']: 
    23312331...            raise ValidationError(u'Please make sure your passwords match.') 
    2332 ...        return self.clean_data['password2'] 
     2332...        return self.cleaned_data['password2'] 
    23332333>>> f = UserRegistration(auto_id=False) 
    23342334>>> f.errors 
     
    23432343>>> f.errors 
    23442344{} 
    2345 >>> f.clean_data 
     2345>>> f.cleaned_data 
    23462346{'username': u'adrian', 'password1': u'foo', 'password2': u'foo'} 
    23472347 
     
    23502350method will not be associated with a particular field; it will have a 
    23512351special-case association with the field named '__all__'. 
    2352 Note that in Form.clean(), you have access to self.clean_data, a dictionary of 
     2352Note that in Form.clean(), you have access to self.cleaned_data, a dictionary of 
    23532353all the fields/values that have *not* raised a ValidationError. Also note 
    23542354Form.clean() is required to return a dictionary of all clean data. 
     
    23582358...    password2 = CharField(widget=PasswordInput) 
    23592359...    def clean(self): 
    2360 ...        if self.clean_data.get('password1') and self.clean_data.get('password2') and self.clean_data['password1'] != self.clean_data['password2']: 
     2360...        if self.cleaned_data.get('password1') and self.cleaned_data.get('password2') and self.cleaned_data['password1'] != self.cleaned_data['password2']: 
    23612361...            raise ValidationError(u'Please make sure your passwords match.') 
    2362 ...        return self.clean_data 
     2362...        return self.cleaned_data 
    23632363>>> f = UserRegistration(auto_id=False) 
    23642364>>> f.errors 
     
    23872387>>> f.errors 
    23882388{} 
    2389 >>> f.clean_data 
     2389>>> f.cleaned_data 
    23902390{'username': u'adrian', 'password1': u'foo', 'password2': u'foo'} 
    23912391 
     
    29552955>>> p.is_valid() 
    29562956True 
    2957 >>> p.clean_data 
     2957>>> p.cleaned_data 
    29582958{'first_name': u'John', 'last_name': u'Lennon', 'birthday': datetime.date(1940, 10, 9)} 
    29592959 
     
    29992999>>> p1.is_valid() 
    30003000True 
    3001 >>> p1.clean_data 
     3001>>> p1.cleaned_data 
    30023002{'first_name': u'John', 'last_name': u'Lennon', 'birthday': datetime.date(1940, 10, 9)} 
    30033003>>> p2 = Person(data, prefix='person2') 
    30043004>>> p2.is_valid() 
    30053005True 
    3006 >>> p2.clean_data 
     3006>>> p2.cleaned_data 
    30073007{'first_name': u'Jim', 'last_name': u'Morrison', 'birthday': datetime.date(1943, 12, 8)} 
    30083008 
     
    30303030>>> p.is_valid() 
    30313031True 
    3032 >>> p.clean_data 
     3032>>> p.cleaned_data 
    30333033{'first_name': u'John', 'last_name': u'Lennon', 'birthday': datetime.date(1940, 10, 9)} 
    30343034 
     
    30923092...    password2 = CharField(widget=PasswordInput) 
    30933093...    def clean(self): 
    3094 ...        if self.clean_data.get('password1') and self.clean_data.get('password2') and self.clean_data['password1'] != self.clean_data['password2']: 
     3094...        if self.cleaned_data.get('password1') and self.cleaned_data.get('password2') and self.cleaned_data['password1'] != self.cleaned_data['password2']: 
    30953095...            raise ValidationError(u'Please make sure your passwords match.') 
    3096 ...        return self.clean_data 
     3096...        return self.cleaned_data 
    30973097>>> def my_function(method, post_data): 
    30983098...     if method == 'POST': 
     
    31013101...         form = UserRegistration(auto_id=False) 
    31023102...     if form.is_valid(): 
    3103 ...         return 'VALID: %r' % form.clean_data 
     3103...         return 'VALID: %r' % form.cleaned_data 
    31043104...     t = Template('<form action="" method="post">\n<table>\n{{ form }}\n</table>\n<input type="submit" />\n</form>') 
    31053105...     return t.render(Context({'form': form})) 
     
    31393139...    password2 = CharField(widget=PasswordInput) 
    31403140...    def clean(self): 
    3141 ...        if self.clean_data.get('password1') and self.clean_data.get('password2') and self.clean_data['password1'] != self.clean_data['password2']: 
     3141...        if self.cleaned_data.get('password1') and self.cleaned_data.get('password2') and self.cleaned_data['password1'] != self.cleaned_data['password2']: 
    31423142...            raise ValidationError(u'Please make sure your passwords match.') 
    3143 ...        return self.clean_data 
     3143...        return self.cleaned_data 
    31443144 
    31453145You have full flexibility in displaying form fields in a template. Just pass a 
     
    34913491<input type="text" name="field1_2_0" value="2007-04-25" id="id_field1_2_0" /><input type="text" name="field1_2_1" value="06:24:00" id="id_field1_2_1" /></td></tr> 
    34923492 
    3493 >>> f.clean_data 
     3493>>> f.cleaned_data 
    34943494{'field1': u'some text,JP,2007-04-25 06:24:00'} 
    34953495 
  • django/branches/unicode/tests/regressiontests/serializers_regress/models.py

    r5185 r5241  
    101101     
    102102    data = models.CharField(maxlength=30) 
     103 
     104class UniqueAnchor(models.Model): 
     105    """This is a model that can be used as  
     106    something for other models to point at""" 
     107 
     108    data = models.CharField(unique=True, maxlength=30) 
    103109     
    104110class FKData(models.Model): 
     
    116122class M2MSelfData(models.Model): 
    117123    data = models.ManyToManyField('self', null=True, symmetrical=False) 
     124 
     125 
     126class FKDataToField(models.Model): 
     127    data = models.ForeignKey(UniqueAnchor, null=True, to_field='data') 
    118128 
    119129# The following test classes are for validating the 
  • django/branches/unicode/tests/regressiontests/serializers_regress/tests.py

    r4752 r5241  
    160160    (data_obj, 300, Anchor, "Anchor 1"), 
    161161    (data_obj, 301, Anchor, "Anchor 2"), 
     162    (data_obj, 302, UniqueAnchor, "UAnchor 1"), 
    162163 
    163164    (fk_obj, 400, FKData, 300), # Post reference 
     
    185186    (m2m_obj, 446, M2MSelfData, []), 
    186187 
     188    (fk_obj, 450, FKDataToField, "UAnchor 1"), 
     189    (fk_obj, 451, FKDataToField, "UAnchor 2"), 
     190    (fk_obj, 452, FKDataToField, None), 
     191     
    187192    (data_obj, 500, Anchor, "Anchor 3"), 
    188193    (data_obj, 501, Anchor, "Anchor 4"), 
     194    (data_obj, 502, UniqueAnchor, "UAnchor 2"), 
    189195 
    190196    (pk_obj, 601, BooleanPKData, True), 
  • django/branches/unicode/tests/regressiontests/test_client_regress/models.py

    r5185 r5241  
    6161        except AssertionError, e: 
    6262            self.assertEquals(str(e), "Template 'Valid POST Template' was not one of the templates used to render the response. Templates used: form_view.html, base.html") 
     63 
     64class AssertRedirectsTests(TestCase): 
     65    def test_redirect_page(self): 
     66        "An assertion is raised if the original page couldn't be retrieved as expected"         
     67        # This page will redirect with code 301, not 302 
     68        response = self.client.get('/test_client/permanent_redirect_view/')         
     69        try: 
     70            self.assertRedirects(response, '/test_client/get_view/') 
     71        except AssertionError, e: 
     72            self.assertEquals(str(e), "Response didn't redirect as expected: Reponse code was 301 (expected 302)") 
     73 
     74    def test_incorrect_target(self): 
     75        "An assertion is raised if the response redirects to another target" 
     76        response = self.client.get('/test_client/permanent_redirect_view/')         
     77        try: 
     78            # Should redirect to get_view 
     79            self.assertRedirects(response, '/test_client/some_view/') 
     80        except AssertionError, e: 
     81            self.assertEquals(str(e), "Response didn't redirect as expected: Reponse code was 301 (expected 302)") 
    6382         
     83    def test_target_page(self): 
     84        "An assertion is raised if the reponse redirect target cannot be retrieved as expected" 
     85        response = self.client.get('/test_client/double_redirect_view/') 
     86        try: 
     87            # The redirect target responds with a 301 code, not 200 
     88            self.assertRedirects(response, '/test_client/permanent_redirect_view/') 
     89        except AssertionError, e: 
     90            self.assertEquals(str(e), "Couldn't retrieve redirection page '/test_client/permanent_redirect_view/': response code was 301 (expected 200)") 
     91             
    6492class AssertFormErrorTests(TestCase): 
    6593    def test_unknown_form(self):