Changeset 5241
- Timestamp:
- 05/14/07 14:42:13 (2 years ago)
- Files:
-
- django/branches/unicode (modified) (1 prop)
- django/branches/unicode/AUTHORS (modified) (1 diff)
- django/branches/unicode/django/conf/global_settings.py (modified) (1 diff)
- django/branches/unicode/django/conf/locale/bg (copied) (copied from django/trunk/django/conf/locale/bg)
- django/branches/unicode/django/conf/locale/bg/LC_MESSAGES (copied) (copied from django/trunk/django/conf/locale/bg/LC_MESSAGES)
- django/branches/unicode/django/conf/locale/bg/LC_MESSAGES/djangojs.mo (copied) (copied from django/trunk/django/conf/locale/bg/LC_MESSAGES/djangojs.mo)
- django/branches/unicode/django/conf/locale/bg/LC_MESSAGES/djangojs.po (copied) (copied from django/trunk/django/conf/locale/bg/LC_MESSAGES/djangojs.po)
- django/branches/unicode/django/conf/locale/bg/LC_MESSAGES/django.mo (copied) (copied from django/trunk/django/conf/locale/bg/LC_MESSAGES/django.mo)
- django/branches/unicode/django/conf/locale/bg/LC_MESSAGES/django.po (copied) (copied from django/trunk/django/conf/locale/bg/LC_MESSAGES/django.po)
- django/branches/unicode/django/contrib/formtools/preview.py (modified) (3 diffs)
- django/branches/unicode/django/core/management.py (modified) (2 diffs)
- django/branches/unicode/django/core/serializers/python.py (modified) (2 diffs)
- django/branches/unicode/django/core/serializers/xml_serializer.py (modified) (2 diffs)
- django/branches/unicode/django/newforms/forms.py (modified) (4 diffs)
- django/branches/unicode/django/newforms/models.py (modified) (3 diffs)
- django/branches/unicode/django/test/testcases.py (modified) (2 diffs)
- django/branches/unicode/docs/newforms.txt (modified) (7 diffs)
- django/branches/unicode/tests/modeltests/model_forms/models.py (modified) (6 diffs)
- django/branches/unicode/tests/regressiontests/forms/regressions.py (modified) (1 diff)
- django/branches/unicode/tests/regressiontests/forms/tests.py (modified) (22 diffs)
- django/branches/unicode/tests/regressiontests/serializers_regress/models.py (modified) (2 diffs)
- django/branches/unicode/tests/regressiontests/serializers_regress/tests.py (modified) (2 diffs)
- django/branches/unicode/tests/regressiontests/test_client_regress/models.py (modified) (1 diff)
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 87 87 deric@monowerks.com 88 88 Max Derkachev <mderk@yandex.ru> 89 Jordan Dimov <s3x3y1@gmail.com> 89 90 dne@mayonnaise.net 90 91 Maximillian Dornseif <md@hudora.de> django/branches/unicode/django/conf/global_settings.py
r5151 r5241 39 39 ('ar', gettext_noop('Arabic')), 40 40 ('bn', gettext_noop('Bengali')), 41 ('bg', gettext_noop('Bulgarian')), 41 42 ('ca', gettext_noop('Catalan')), 42 43 ('cs', gettext_noop('Czech')), django/branches/unicode/django/contrib/formtools/preview.py
r4265 r5241 25 25 Subclass FormPreview and define a done() method: 26 26 27 def done(self, request, clean _data):27 def done(self, request, cleaned_data): 28 28 # ... 29 29 … … 114 114 if self.security_hash(request, f) != request.POST.get(self.unused_name('hash')): 115 115 return self.failed_hash(request) # Security hash failed. 116 return self.done(request, f.clean _data)116 return self.done(request, f.cleaned_data) 117 117 else: 118 118 return render_to_response(self.form_template, … … 161 161 # METHODS SUBCLASSES MUST OVERRIDE ######################################## 162 162 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 """ 165 168 raise NotImplementedError('You must define a done() method on your %s subclass.' % self.__class__.__name__) django/branches/unicode/django/core/management.py
r5185 r5241 1405 1405 print "No %s fixture '%s' in %s." % \ 1406 1406 (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 1407 1419 if count[0] == 0: 1408 1420 if verbosity > 0: … … 1411 1423 if verbosity > 0: 1412 1424 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()1421 1425 1422 1426 load_data.help_doc = 'Installs the named fixture(s) in the database' django/branches/unicode/django/core/serializers/python.py
r4718 r5241 38 38 related = getattr(obj, field.name) 39 39 if related is not None: 40 related = related._get_pk_val()40 related = getattr(related, field.rel.field_name) 41 41 self._current[field.name] = related 42 42 … … 81 81 # Handle FK fields 82 82 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 84 87 85 88 # Handle all other fields django/branches/unicode/django/core/serializers/xml_serializer.py
r4733 r5241 83 83 related = getattr(obj, field.name) 84 84 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))) 86 86 else: 87 87 self.xml.addQuickElement("None") … … 182 182 return None 183 183 else: 184 return field.rel.to._meta. pk.to_python(184 return field.rel.to._meta.get_field(field.rel.field_name).to_python( 185 185 getInnerText(node).strip().encode(self.encoding)) 186 186 django/branches/unicode/django/newforms/forms.py
r5236 r5241 170 170 def full_clean(self): 171 171 """ 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. 173 173 """ 174 174 errors = ErrorDict() … … 176 176 self.__errors = errors 177 177 return 178 self.clean _data = {}178 self.cleaned_data = {} 179 179 for name, field in self.fields.items(): 180 180 # value_from_datadict() gets the data from the dictionary. … … 184 184 try: 185 185 value = field.clean(value) 186 self.clean _data[name] = value186 self.cleaned_data[name] = value 187 187 if hasattr(self, 'clean_%s' % name): 188 188 value = getattr(self, 'clean_%s' % name)() 189 self.clean _data[name] = value189 self.cleaned_data[name] = value 190 190 except ValidationError, e: 191 191 errors[name] = e.messages 192 192 try: 193 self.clean _data = self.clean()193 self.cleaned_data = self.clean() 194 194 except ValidationError, e: 195 195 errors[NON_FIELD_ERRORS] = e.messages 196 196 if errors: 197 delattr(self, 'clean _data')197 delattr(self, 'cleaned_data') 198 198 self.__errors = errors 199 199 … … 205 205 association with the field named '__all__'. 206 206 """ 207 return self.clean _data207 return self.cleaned_data 208 208 209 209 class Form(BaseForm): django/branches/unicode/django/newforms/models.py
r5236 r5241 16 16 def save_instance(form, instance, fields=None, fail_message='saved', commit=True): 17 17 """ 18 Saves bound Form ``form``'s clean _data into model instance ``instance``.18 Saves bound Form ``form``'s cleaned_data into model instance ``instance``. 19 19 20 20 Assumes ``form`` has a field for every non-AutoField database field in … … 26 26 if form.errors: 27 27 raise ValueError("The %s could not be %s because the data didn't validate." % (opts.object_name, fail_message)) 28 clean _data = form.clean_data28 cleaned_data = form.cleaned_data 29 29 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: 31 31 continue 32 32 if fields and f.name not in fields: 33 33 continue 34 setattr(instance, f.name, clean _data[f.name])34 setattr(instance, f.name, cleaned_data[f.name]) 35 35 if commit: 36 36 instance.save() … … 38 38 if fields and f.name not in fields: 39 39 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]) 42 42 # GOTCHA: If many-to-many data is given and commit=False, the many-to-many 43 43 # data will be lost. This happens because a many-to-many options cannot be django/branches/unicode/django/test/testcases.py
r5224 r5241 63 63 """ 64 64 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)" % 66 66 (response.status_code, status_code)) 67 67 scheme, netloc, path, params, query, fragment = urlparse(response['Location']) … … 71 71 self.assertEqual(redirect_response.status_code, target_status_code, 72 72 "Couldn't retrieve redirection page '%s': response code was %d (expected %d)" % 73 (path, re sponse.status_code,status_code))73 (path, redirect_response.status_code, target_status_code)) 74 74 75 75 def assertContains(self, response, text, count=1, status_code=200): django/branches/unicode/docs/newforms.txt
r5224 r5241 231 231 232 232 Once 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``233 you can access the clean data via the ``cleaned_data`` attribute of the ``Form`` 234 234 object:: 235 235 … … 241 241 >>> f.is_valid() 242 242 True 243 >>> f.clean _data243 >>> f.cleaned_data 244 244 {'cc_myself': True, 'message': u'Hi there', 'sender': u'foo@example.com', 'subject': u'hello'} 245 245 … … 249 249 250 250 If your data does *not* validate, your ``Form`` instance will not have a 251 ``clean _data`` attribute::251 ``cleaned_data`` attribute:: 252 252 253 253 >>> data = {'subject': '', … … 258 258 >>> f.is_valid() 259 259 False 260 >>> f.clean _data260 >>> f.cleaned_data 261 261 Traceback (most recent call last): 262 262 ... 263 AttributeError: 'ContactForm' object has no attribute 'clean _data'264 265 ``clean _data`` will always *only* contain a key for fields defined in the263 AttributeError: 'ContactForm' object has no attribute 'cleaned_data' 264 265 ``cleaned_data`` will always *only* contain a key for fields defined in the 266 266 ``Form``, even if you pass extra data when you define the ``Form``. In this 267 267 example, we pass a bunch of extra fields to the ``ContactForm`` constructor, 268 but ``clean _data`` contains only the form's fields::268 but ``cleaned_data`` contains only the form's fields:: 269 269 270 270 >>> data = {'subject': 'hello', … … 278 278 >>> f.is_valid() 279 279 True 280 >>> f.clean _data # Doesn't contain extra_field_1, etc.280 >>> f.cleaned_data # Doesn't contain extra_field_1, etc. 281 281 {'cc_myself': True, 'message': u'Hi there', 'sender': u'foo@example.com', 'subject': u'hello'} 282 282 283 ``clean _data`` will include a key and value for *all* fields defined in the283 ``cleaned_data`` will include a key and value for *all* fields defined in the 284 284 ``Form``, even if the data didn't include a value for fields that are not 285 285 required. 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:: 287 287 288 288 >>> class OptionalPersonForm(Form): … … 294 294 >>> f.is_valid() 295 295 True 296 >>> f.clean _data296 >>> f.cleaned_data 297 297 {'nick_name': u'', 'first_name': u'John', 'last_name': u'Lennon'} 298 298 299 In this above example, the ``clean _data`` value for ``nick_name`` is set to an299 In this above example, the ``cleaned_data`` value for ``nick_name`` is set to an 300 300 empty string, because ``nick_name`` is ``CharField``, and ``CharField``\s treat 301 301 empty values as an empty string. Each field type knows what its "blank" value … … 309 309 310 310 >>> f = ContactForm() 311 >>> f.clean _data311 >>> f.cleaned_data 312 312 Traceback (most recent call last): 313 313 ... 314 AttributeError: 'ContactForm' object has no attribute 'clean _data'314 AttributeError: 'ContactForm' object has no attribute 'cleaned_data' 315 315 316 316 Outputting forms as HTML django/branches/unicode/tests/modeltests/model_forms/models.py
r5214 r5241 19 19 20 20 The 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 takes21 model instance and saves the form's cleaned_data into the instance. It also takes 22 22 a commit=True parameter. 23 23 """ … … 95 95 >>> f.is_valid() 96 96 True 97 >>> f.clean _data97 >>> f.cleaned_data 98 98 {'url': u'entertainment', 'name': u'Entertainment'} 99 99 >>> obj = f.save() … … 106 106 >>> f.is_valid() 107 107 True 108 >>> f.clean _data108 >>> f.cleaned_data 109 109 {'url': u'test', 'name': u"It's a test"} 110 110 >>> obj = f.save() … … 120 120 >>> f.is_valid() 121 121 True 122 >>> f.clean _data122 >>> f.cleaned_data 123 123 {'url': u'third', 'name': u'Third test'} 124 124 >>> obj = f.save(commit=False) … … 135 135 >>> f.errors 136 136 {'name': [u'This field is required.']} 137 >>> f.clean _data138 Traceback (most recent call last): 139 ... 140 AttributeError: 'CategoryForm' object has no attribute 'clean _data'137 >>> f.cleaned_data 138 Traceback (most recent call last): 139 ... 140 AttributeError: 'CategoryForm' object has no attribute 'cleaned_data' 141 141 >>> f.save() 142 142 Traceback (most recent call last): … … 525 525 >>> f.is_valid() 526 526 True 527 >>> f.clean _data527 >>> f.cleaned_data 528 528 {'phone': u'312-555-1212', 'description': u'Assistance'} 529 529 """} django/branches/unicode/tests/regressiontests/forms/regressions.py
r5238 r5241 53 53 >>> f.clean('\xd1\x88\xd1\x82.') 54 54 u'\u0448\u0442.' 55 56 ####################### 57 # Miscellaneous Tests # 58 ####################### 59 60 There once was a problem with Form fields called "data". Let's make sure that 61 doesn't come back. 62 >>> class DataForm(Form): 63 ... data = CharField(max_length=10) 64 >>> f = DataForm({'data': 'xyzzy'}) 65 >>> f.is_valid() 66 True 67 >>> f.cleaned_data 68 {'data': u'xyzzy'} 55 69 """ django/branches/unicode/tests/regressiontests/forms/tests.py
r5224 r5241 1775 1775 >>> p.errors.as_text() 1776 1776 u'' 1777 >>> p.clean _data1777 >>> p.cleaned_data 1778 1778 {'first_name': u'John', 'last_name': u'Lennon', 'birthday': datetime.date(1940, 10, 9)} 1779 1779 >>> print p['first_name'] … … 1811 1811 >>> p.is_valid() 1812 1812 False 1813 >>> p.clean _data1814 Traceback (most recent call last): 1815 ... 1816 AttributeError: 'Person' object has no attribute 'clean _data'1813 >>> p.cleaned_data 1814 Traceback (most recent call last): 1815 ... 1816 AttributeError: 'Person' object has no attribute 'cleaned_data' 1817 1817 >>> print p 1818 1818 <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> … … 1845 1845 >>> p.is_valid() 1846 1846 False 1847 >>> p.clean _data1848 Traceback (most recent call last): 1849 ... 1850 AttributeError: 'Person' object has no attribute 'clean _data'1847 >>> p.cleaned_data 1848 Traceback (most recent call last): 1849 ... 1850 AttributeError: 'Person' object has no attribute 'cleaned_data' 1851 1851 >>> print p 1852 1852 <tr><th><label for="id_first_name">First name:</label></th><td><input type="text" name="first_name" id="id_first_name" /></td></tr> … … 1887 1887 * birthday 1888 1888 * This field is required. 1889 >>> p.clean _data1890 Traceback (most recent call last): 1891 ... 1892 AttributeError: 'Person' object has no attribute 'clean _data'1889 >>> p.cleaned_data 1890 Traceback (most recent call last): 1891 ... 1892 AttributeError: 'Person' object has no attribute 'cleaned_data' 1893 1893 >>> p['first_name'].errors 1894 1894 [u'This field is required.'] … … 1906 1906 <input type="text" name="birthday" id="id_birthday" /> 1907 1907 1908 clean _data will always *only* contain a key for fields defined in the1908 cleaned_data will always *only* contain a key for fields defined in the 1909 1909 Form, even if you pass extra data when you define the Form. In this 1910 1910 example, we pass a bunch of extra fields to the form constructor, 1911 but clean _data contains only the form's fields.1911 but cleaned_data contains only the form's fields. 1912 1912 >>> data = {'first_name': u'John', 'last_name': u'Lennon', 'birthday': u'1940-10-9', 'extra1': 'hello', 'extra2': 'hello'} 1913 1913 >>> p = Person(data) 1914 1914 >>> p.is_valid() 1915 1915 True 1916 >>> p.clean _data1916 >>> p.cleaned_data 1917 1917 {'first_name': u'John', 'last_name': u'Lennon', 'birthday': datetime.date(1940, 10, 9)} 1918 1918 1919 clean _data will include a key and value for *all* fields defined in the Form,1919 cleaned_data will include a key and value for *all* fields defined in the Form, 1920 1920 even if the Form's data didn't include a value for fields that are not 1921 1921 required. 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 the1922 "nick_name" field, but cleaned_data includes it. For CharFields, it's set to the 1923 1923 empty string. 1924 1924 >>> class OptionalPersonForm(Form): … … 1930 1930 >>> f.is_valid() 1931 1931 True 1932 >>> f.clean _data1932 >>> f.cleaned_data 1933 1933 {'nick_name': u'', 'first_name': u'John', 'last_name': u'Lennon'} 1934 1934 … … 1942 1942 >>> f.is_valid() 1943 1943 True 1944 >>> f.clean _data1944 >>> f.cleaned_data 1945 1945 {'birth_date': None, 'first_name': u'John', 'last_name': u'Lennon'} 1946 1946 … … 2293 2293 >>> f.errors 2294 2294 {} 2295 >>> f.clean _data2295 >>> f.cleaned_data 2296 2296 {'composers': [u'J'], 'name': u'Yesterday'} 2297 2297 >>> f = SongForm({'name': 'Yesterday', 'composers': ['J', 'P']}, auto_id=False) 2298 2298 >>> f.errors 2299 2299 {} 2300 >>> f.clean _data2300 >>> f.cleaned_data 2301 2301 {'composers': [u'J', u'P'], 'name': u'Yesterday'} 2302 2302 … … 2305 2305 ... special_name = CharField() 2306 2306 ... 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']) 2308 2308 2309 2309 >>> f = EscapingForm({'special_name': "Nothing to escape"}, auto_id=False) … … 2320 2320 clean_XXX() method on the Form, where XXX is the field name. As in 2321 2321 Field.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 dictionary2322 clean_XXX() method, you have access to self.cleaned_data, which is a dictionary 2323 2323 of all the data that has been cleaned *so far*, in order by the fields, 2324 2324 including the current field (e.g., the field XXX if you're in clean_XXX()). … … 2328 2328 ... password2 = CharField(widget=PasswordInput) 2329 2329 ... 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']: 2331 2331 ... raise ValidationError(u'Please make sure your passwords match.') 2332 ... return self.clean _data['password2']2332 ... return self.cleaned_data['password2'] 2333 2333 >>> f = UserRegistration(auto_id=False) 2334 2334 >>> f.errors … … 2343 2343 >>> f.errors 2344 2344 {} 2345 >>> f.clean _data2345 >>> f.cleaned_data 2346 2346 {'username': u'adrian', 'password1': u'foo', 'password2': u'foo'} 2347 2347 … … 2350 2350 method will not be associated with a particular field; it will have a 2351 2351 special-case association with the field named '__all__'. 2352 Note that in Form.clean(), you have access to self.clean _data, a dictionary of2352 Note that in Form.clean(), you have access to self.cleaned_data, a dictionary of 2353 2353 all the fields/values that have *not* raised a ValidationError. Also note 2354 2354 Form.clean() is required to return a dictionary of all clean data. … … 2358 2358 ... password2 = CharField(widget=PasswordInput) 2359 2359 ... 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']: 2361 2361 ... raise ValidationError(u'Please make sure your passwords match.') 2362 ... return self.clean _data2362 ... return self.cleaned_data 2363 2363 >>> f = UserRegistration(auto_id=False) 2364 2364 >>> f.errors … … 2387 2387 >>> f.errors 2388 2388 {} 2389 >>> f.clean _data2389 >>> f.cleaned_data 2390 2390 {'username': u'adrian', 'password1': u'foo', 'password2': u'foo'} 2391 2391 … … 2955 2955 >>> p.is_valid() 2956 2956 True 2957 >>> p.clean _data2957 >>> p.cleaned_data 2958 2958 {'first_name': u'John', 'last_name': u'Lennon', 'birthday': datetime.date(1940, 10, 9)} 2959 2959 … … 2999 2999 >>> p1.is_valid() 3000 3000 True 3001 >>> p1.clean _data3001 >>> p1.cleaned_data 3002 3002 {'first_name': u'John', 'last_name': u'Lennon', 'birthday': datetime.date(1940, 10, 9)} 3003 3003 >>> p2 = Person(data, prefix='person2') 3004 3004 >>> p2.is_valid() 3005 3005 True 3006 >>> p2.clean _data3006 >>> p2.cleaned_data 3007 3007 {'first_name': u'Jim', 'last_name': u'Morrison', 'birthday': datetime.date(1943, 12, 8)} 3008 3008 … … 3030 3030 >>> p.is_valid() 3031 3031 True 3032 >>> p.clean _data3032 >>> p.cleaned_data 3033 3033 {'first_name': u'John', 'last_name': u'Lennon', 'birthday': datetime.date(1940, 10, 9)} 3034 3034 … … 3092 3092 ... password2 = CharField(widget=PasswordInput) 3093 3093 ... 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']: 3095 3095 ... raise ValidationError(u'Please make sure your passwords match.') 3096 ... return self.clean _data3096 ... return self.cleaned_data 3097 3097 >>> def my_function(method, post_data): 3098 3098 ... if method == 'POST': … … 3101 3101 ... form = UserRegistration(auto_id=False) 3102 3102 ... if form.is_valid(): 3103 ... return 'VALID: %r' % form.clean _data3103 ... return 'VALID: %r' % form.cleaned_data 3104 3104 ... t = Template('<form action="" method="post">\n<table>\n{{ form }}\n</table>\n<input type="submit" />\n</form>') 3105 3105 ... return t.render(Context({'form': form})) … … 3139 3139 ... password2 = CharField(widget=PasswordInput) 3140 3140 ... 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']: 3142 3142 ... raise ValidationError(u'Please make sure your passwords match.') 3143 ... return self.clean _data3143 ... return self.cleaned_data 3144 3144 3145 3145 You have full flexibility in displaying form fields in a template. Just pass a … … 3491 3491 <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> 3492 3492 3493 >>> f.clean _data3493 >>> f.cleaned_data 3494 3494 {'field1': u'some text,JP,2007-04-25 06:24:00'} 3495 3495 django/branches/unicode/tests/regressiontests/serializers_regress/models.py
r5185 r5241 101 101 102 102 data = models.CharField(maxlength=30) 103 104 class 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) 103 109 104 110 class FKData(models.Model): … … 116 122 class M2MSelfData(models.Model): 117 123 data = models.ManyToManyField('self', null=True, symmetrical=False) 124 125 126 class FKDataToField(models.Model): 127 data = models.ForeignKey(UniqueAnchor, null=True, to_field='data') 118 128 119 129 # The following test classes are for validating the django/branches/unicode/tests/regressiontests/serializers_regress/tests.py
r4752 r5241 160 160 (data_obj, 300, Anchor, "Anchor 1"), 161 161 (data_obj, 301, Anchor, "Anchor 2"), 162 (data_obj, 302, UniqueAnchor, "UAnchor 1"), 162 163 163 164 (fk_obj, 400, FKData, 300), # Post reference … … 185 186 (m2m_obj, 446, M2MSelfData, []), 186 187 188 (fk_obj, 450, FKDataToField, "UAnchor 1"), 189 (fk_obj, 451, FKDataToField, "UAnchor 2"), 190 (fk_obj, 452, FKDataToField, None), 191 187 192 (data_obj, 500, Anchor, "Anchor 3"), 188 193 (data_obj, 501, Anchor, "Anchor 4"), 194 (data_obj, 502, UniqueAnchor, "UAnchor 2"), 189 195 190 196 (pk_obj, 601, BooleanPKData, True), django/branches/unicode/tests/regressiontests/test_client_regress/models.py
r5185 r5241 61 61 except AssertionError, e: 62 62 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 64 class 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)") 63 82 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 64 92 class AssertFormErrorTests(TestCase): 65 93 def test_unknown_form(self):
