Changeset 5462
- Timestamp:
- 06/11/07 09:51:26 (1 year ago)
- Files:
-
- django/branches/unicode (modified) (1 prop)
- django/branches/unicode/AUTHORS (modified) (4 diffs)
- django/branches/unicode/django/conf/global_settings.py (modified) (1 diff)
- django/branches/unicode/django/conf/locale/nl/LC_MESSAGES/django.mo (modified) (previous)
- django/branches/unicode/django/conf/locale/nl/LC_MESSAGES/django.po (modified) (1 diff)
- django/branches/unicode/django/core/management.py (modified) (2 diffs)
- django/branches/unicode/django/db/backends/postgresql/base.py (modified) (1 diff)
- django/branches/unicode/django/db/backends/postgresql_psycopg2/base.py (modified) (1 diff)
- django/branches/unicode/django/db/backends/util.py (modified) (1 diff)
- django/branches/unicode/django/__init__.py (modified) (1 diff)
- django/branches/unicode/django/template/defaulttags.py (modified) (2 diffs)
- django/branches/unicode/django/views/debug.py (modified) (3 diffs)
- django/branches/unicode/docs/authentication.txt (modified) (1 diff)
- django/branches/unicode/docs/db-api.txt (modified) (2 diffs)
- django/branches/unicode/docs/man (copied) (copied from django/trunk/docs/man)
- django/branches/unicode/docs/man/django-admin.1 (copied) (copied from django/trunk/docs/man/django-admin.1)
- django/branches/unicode/docs/model-api.txt (modified) (1 diff)
- django/branches/unicode/docs/newforms.txt (modified) (2 diffs)
- django/branches/unicode/scripts/rpm-install.sh (modified) (1 diff)
- django/branches/unicode/tests/regressiontests/serializers_regress/tests.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/unicode
- Property svnmerge-integrated changed from /django/trunk:1-5443 to /django/trunk:1-5460
django/branches/unicode/AUTHORS
r5419 r5462 74 74 Ian Clelland <clelland@gmail.com> 75 75 crankycoder@gmail.com 76 Pete Crosier <pete.crosier@gmail.com> 76 77 Matt Croydon <http://www.postneo.com/> 77 78 flavio.curella@gmail.com … … 132 133 Antti Kaihola <http://akaihola.blogspot.com/> 133 134 Ben Dean Kawamura <ben.dean.kawamura@gmail.com> 135 ian.g.kelly@gmail.com 134 136 Garth Kidd <http://www.deadlybloodyserious.com/> 135 137 kilian <kilian.cavalotti@lip6.fr> … … 172 174 mmarshall 173 175 Eric Moritz <http://eric.themoritzfamily.com/> 176 mrmachine <real.human@mrmachine.net> 174 177 Robin Munn <http://www.geekforgod.com/> 175 178 Robert Myers <myer0052@gmail.com> … … 237 240 Dan Watson <http://theidioteque.net/> 238 241 Chris Wesseling <Chris.Wesseling@cwi.nl> 242 James Wheare <django@sparemint.com> 239 243 charly.wilhelm@gmail.com 240 244 Rachel Willmer <http://www.willmer.com/kb/> django/branches/unicode/django/conf/global_settings.py
r5381 r5462 245 245 # The User-Agent string to use when checking for URL validity through the 246 246 # isExistingURL validator. 247 URL_VALIDATOR_USER_AGENT = "Django/0.96pre (http://www.djangoproject.com)" 247 from django import get_version 248 URL_VALIDATOR_USER_AGENT = "Django/%s (http://www.djangoproject.com)" % get_version() 248 249 249 250 ############## django/branches/unicode/django/conf/locale/nl/LC_MESSAGES/django.po
r4530 r5462 2203 2203 2204 2204 #: utils/timesince.py:16 2205 # In the timesince context it is stilistically wrong to use the plural for hour in Dutch. 2205 2206 msgid "hour" 2206 2207 msgid_plural "hours" 2207 2208 msgstr[0] "uur" 2208 msgstr[1] "u ren"2209 msgstr[1] "uur" 2209 2210 2210 2211 #: utils/timesince.py:17 django/branches/unicode/django/core/management.py
r5381 r5462 4 4 import django 5 5 from django.core.exceptions import ImproperlyConfigured 6 import os, re, shutil, sys, textwrap7 6 from optparse import OptionParser 8 7 from django.utils import termcolors 8 import os, re, shutil, sys, textwrap 9 9 10 10 # For Python 2.3 11 11 if not hasattr(__builtins__, 'set'): 12 12 from sets import Set as set 13 14 # For backwards compatibility: get_version() used to be in this module. 15 get_version = django.get_version 13 16 14 17 MODULE_TEMPLATE = ''' {%% if perms.%(app)s.%(addperm)s or perms.%(app)s.%(changeperm)s %%} … … 93 96 # field as the field to which it points. 94 97 get_rel_data_type = lambda f: (f.get_internal_type() in ('AutoField', 'PositiveIntegerField', 'PositiveSmallIntegerField')) and 'IntegerField' or f.get_internal_type() 95 96 def get_version():97 "Returns the version as a human-format string."98 from django import VERSION99 v = '.'.join([str(i) for i in VERSION[:-1]])100 if VERSION[-1]:101 v += '-' + VERSION[-1]102 return v103 98 104 99 def get_sql_create(app): django/branches/unicode/django/db/backends/postgresql/base.py
r5310 r5462 240 240 output = [] 241 241 for model in model_list: 242 # Use `coalesce` to set the sequence for each model to the max pk value if there are records, 243 # or 1 if there are none. Set the `is_called` property (the third argument to `setval`) to true 244 # if there are records (as the max pk value is already in use), otherwise set it to false. 242 245 for f in model._meta.fields: 243 246 if isinstance(f, models.AutoField): 244 output.append("%s setval('%s', (%s max(%s) %s %s));" % \247 output.append("%s setval('%s', coalesce(max(%s), 1), max(%s) %s null) %s %s;" % \ 245 248 (style.SQL_KEYWORD('SELECT'), 246 249 style.SQL_FIELD(quote_name('%s_%s_seq' % (model._meta.db_table, f.column))), 247 style.SQL_KEYWORD('SELECT'),248 250 style.SQL_FIELD(quote_name(f.column)), 251 style.SQL_FIELD(quote_name(f.column)), 252 style.SQL_KEYWORD('IS NOT'), 249 253 style.SQL_KEYWORD('FROM'), 250 254 style.SQL_TABLE(quote_name(model._meta.db_table)))) 251 255 break # Only one AutoField is allowed per model, so don't bother continuing. 252 256 for f in model._meta.many_to_many: 253 output.append("%s setval('%s', (%s max(%s) %s %s));" % \257 output.append("%s setval('%s', coalesce(max(%s), 1), max(%s) %s null) %s %s;" % \ 254 258 (style.SQL_KEYWORD('SELECT'), 255 259 style.SQL_FIELD(quote_name('%s_id_seq' % f.m2m_db_table())), 256 style.SQL_KEYWORD('SELECT'),257 260 style.SQL_FIELD(quote_name('id')), 261 style.SQL_FIELD(quote_name('id')), 262 style.SQL_KEYWORD('IS NOT'), 258 263 style.SQL_KEYWORD('FROM'), 259 264 style.SQL_TABLE(f.m2m_db_table()))) django/branches/unicode/django/db/backends/postgresql_psycopg2/base.py
r5214 r5462 181 181 output = [] 182 182 for model in model_list: 183 # Use `coalesce` to set the sequence for each model to the max pk value if there are records, 184 # or 1 if there are none. Set the `is_called` property (the third argument to `setval`) to true 185 # if there are records (as the max pk value is already in use), otherwise set it to false. 183 186 for f in model._meta.fields: 184 187 if isinstance(f, models.AutoField): 185 output.append("%s setval('%s', (%s max(%s) %s %s));" % \188 output.append("%s setval('%s', coalesce(max(%s), 1), max(%s) %s null) %s %s;" % \ 186 189 (style.SQL_KEYWORD('SELECT'), 187 190 style.SQL_FIELD(quote_name('%s_%s_seq' % (model._meta.db_table, f.column))), 188 style.SQL_KEYWORD('SELECT'),189 191 style.SQL_FIELD(quote_name(f.column)), 192 style.SQL_FIELD(quote_name(f.column)), 193 style.SQL_KEYWORD('IS NOT'), 190 194 style.SQL_KEYWORD('FROM'), 191 195 style.SQL_TABLE(quote_name(model._meta.db_table)))) 192 196 break # Only one AutoField is allowed per model, so don't bother continuing. 193 197 for f in model._meta.many_to_many: 194 output.append("%s setval('%s', (%s max(%s) %s %s));" % \198 output.append("%s setval('%s', coalesce(max(%s), 1), max(%s) %s null) %s %s;" % \ 195 199 (style.SQL_KEYWORD('SELECT'), 196 200 style.SQL_FIELD(quote_name('%s_id_seq' % f.m2m_db_table())), 197 style.SQL_KEYWORD('SELECT'),198 201 style.SQL_FIELD(quote_name('id')), 202 style.SQL_FIELD(quote_name('id')), 203 style.SQL_KEYWORD('IS NOT'), 199 204 style.SQL_KEYWORD('FROM'), 200 205 style.SQL_TABLE(f.m2m_db_table()))) django/branches/unicode/django/db/backends/util.py
r5400 r5462 99 99 100 100 def typecast_decimal(s): 101 if s is None :101 if s is None or s == '': 102 102 return None 103 103 return decimal.Decimal(s) django/branches/unicode/django/__init__.py
r4914 r5462 1 1 VERSION = (0, 97, 'pre') 2 3 def get_version(): 4 "Returns the version as a human-format string." 5 v = '.'.join([str(i) for i in VERSION[:-1]]) 6 if VERSION[-1]: 7 v += '-' + VERSION[-1] 8 return v django/branches/unicode/django/template/defaulttags.py
r5446 r5462 8 8 import sys 9 9 import re 10 11 if not hasattr(__builtins__, 'reversed'): 12 # For Python 2.3. 13 # From http://www.python.org/doc/current/tut/node11.html 14 def reversed(data): 15 for index in xrange(len(data)-1, -1, -1): 16 yield data[index] 17 10 18 11 19 register = Library() … … 105 113 len_values = len(values) 106 114 if self.reversed: 107 # From http://www.python.org/doc/current/tut/node11.html 108 def reverse(data): 109 for index in range(len(data)-1, -1, -1): 110 yield data[index] 111 values = reverse(values) 115 values = reversed(values) 112 116 unpack = len(self.loopvars) > 1 113 117 for i, item in enumerate(values): django/branches/unicode/django/views/debug.py
r5316 r5462 4 4 from django.http import HttpResponseServerError, HttpResponseNotFound 5 5 from django.utils.encoding import smart_unicode 6 import os, re 6 import os, re, sys 7 7 8 8 HIDDEN_SETTINGS = re.compile('SECRET|PASSWORD|PROFANITIES_LIST') … … 133 133 'request_protocol': request.is_secure() and "https" or "http", 134 134 'settings': get_safe_settings(), 135 'sys_executable' : sys.executable, 136 'sys_version_info' : '%d.%d.%d' % sys.version_info[0:3], 135 137 'template_info': template_info, 136 138 'template_does_not_exist': template_does_not_exist, … … 347 349 <td>{{ lastframe.filename|escape }} in {{ lastframe.function|escape }}, line {{ lastframe.lineno }}</td> 348 350 </tr> 351 <tr> 352 <th>Python Executable:</th> 353 <td>{{ sys_executable|escape }}</td> 354 </tr> 355 <tr> 356 <th>Python Version:</th> 357 <td>{{ sys_version_info }}</td> 358 </tr> 349 359 </table> 350 360 </div> django/branches/unicode/docs/authentication.txt
r5126 r5462 731 731 ------------------- 732 732 733 Three basic permissions -- add, c reate and delete -- are automatically created733 Three basic permissions -- add, change and delete -- are automatically created 734 734 for each Django model that has a ``class Admin`` set. Behind the scenes, these 735 735 permissions are added to the ``auth_permission`` database table when you run django/branches/unicode/docs/db-api.txt
r5444 r5462 389 389 underlying SQL statement, and the whole thing is enclosed in a ``NOT()``. 390 390 391 This example excludes all entries whose ``pub_date`` is the current date/time391 This example excludes all entries whose ``pub_date`` is later than 2005-1-3 392 392 AND whose ``headline`` is "Hello":: 393 393 … … 399 399 WHERE NOT (pub_date > '2005-1-3' AND headline = 'Hello') 400 400 401 This example excludes all entries whose ``pub_date`` is the current date/time402 OR whose ``headline`` is"Hello"::401 This example excludes all entries whose ``pub_date`` is later than 2005-1-3 402 AND whose headline is NOT "Hello":: 403 403 404 404 Entry.objects.exclude(pub_date__gt=datetime.date(2005, 1, 3)).exclude(headline='Hello') django/branches/unicode/docs/model-api.txt
r5444 r5462 447 447 448 448 The admin represents this as an ``<input type="text">`` (a single-line input). 449 450 ``URLField`` takes an optional argument, ``maxlength``, the maximum length (in 451 characters) of the field. The maxlength is enforced at the database level and 452 in Django's validation. If you don't specify ``maxlength``, a default of 200 453 is used. 449 454 450 455 ``USStateField`` django/branches/unicode/docs/newforms.txt
r5444 r5462 303 303 full details on each field's behavior in this case, see the "Empty value" note 304 304 for each field in the "Built-in ``Field`` classes" section below. 305 306 You can write code to perform validation for particular form fields (based on 307 their name) or for the form as a whole (considering combinations of various 308 fields). More information about this is in the `Custom form and field 309 validation`_ section, below. 305 310 306 311 Behavior of unbound forms … … 1212 1217 mentioned above (``required``, ``label``, ``initial``, ``widget``, 1213 1218 ``help_text``). 1219 1220 Custom form and field validation 1221 --------------------------------- 1222 1223 Form validation happens when the data is cleaned. If you want to customise 1224 this process, there are various places you can change, each one serving a 1225 different purpose. Thee types of cleaning methods are run during form 1226 processing. These are normally executed when you call the ``is_valid()`` 1227 method on a form. There are other things that can kick of cleaning and 1228 validation (accessing the ``errors`` attribute or calling ``full_clean()`` 1229 directly), but normally they won't be needed. 1230 1231 In general, any cleaning method can raise ``ValidationError`` if there is a 1232 problem with the data it is processing, passing the relevant error message to 1233 the ``ValidationError`` constructor. If no ``ValidationError`` is raised, the 1234 method should return the cleaned (normalised) data as a Python object. 1235 1236 If you detect multiple errors during a cleaning method and wish to signal all 1237 of them to the form submittor, it is possible to pass a list of errors to the 1238 ``ValidationError`` constructor. 1239 1240 The three types of cleaning methods are: 1241 1242 * The ``clean()`` method on a Field subclass. This is responsible 1243 for cleaning the data in a way that is generic for that type of field. 1244 For example, a FloatField will turn the data into a Python ``float`` or 1245 raise a ``ValidationError``. 1246 1247 * The ``clean_<fieldname>()`` method in a form subclass -- where 1248 ``<fieldname>`` is replaced with the name of the form field attribute. 1249 This method does any cleaning that is specific to that particular 1250 attribute, unrelated to the type of field that it is. This method is not 1251 passed any parameters. You will need to look up the value of the field 1252 in ``self.cleaned_data`` and remember that it will be a Python object 1253 at this point, not the original string submitted in the form (it will be 1254 in ``cleaned_data`` because the general field ``clean()`` method, above, 1255 has already cleaned the data once). 1256 1257 For example, if you wanted to validate that the contents of a 1258 ``CharField`` called ``serialnumber`` was unique, 1259 ``clean_serialnumber()`` would be the right place to do this. You don't 1260 need a specific field (it's just a ``CharField``), but you want a 1261 formfield-specific piece of validation and, possibly, 1262 cleaning/normalizing the data. 1263 1264 * The Form subclass's ``clean()`` method. This method can perform 1265 any validation that requires access to multiple fields from the form at 1266 once. This is where you might put in things to check that if field ``A`` 1267 is supplied, field ``B`` must contain a valid email address and the 1268 like. The data that this method returns is the final ``cleaned_data`` 1269 attribute for the form, so don't forget to return the full list of 1270 cleaned data if you override this method (by default, ``Form.clean()`` 1271 just returns ``self.cleaned_data``). 1272 1273 Note that any errors raised by your ``Form.clean()`` override will not 1274 be associated with any field in particular. They go into a special 1275 "field" (called ``__all__``, which you can access via the 1276 ``non_field_errors()`` method if you need to. 1277 1278 These methods are run in the order given above, one field at a time. That is, 1279 for each field in the form (in the order they are declared in the form 1280 definition), the ``Field.clean()`` method (or it's override) is run, then 1281 ``clean_<fieldname>()``. Finally, once those two methods are run for every 1282 field, the ``Form.clean()`` method, or it's override, is executed. 1283 1284 As mentioned above, any of these methods can raise a ``ValidationError``. For 1285 any field, if the ``Field.clean()`` method raises a ``ValidationError``, any 1286 field-specific cleaning method is not called. However, the cleaning methods 1287 for all remaining fields are still executed. 1288 1289 The ``clean()`` method for the ``Form`` class or subclass is always run. If 1290 that method raises a ``ValidationError``, ``cleaned_data`` will be an empty 1291 dictionary. 1292 1293 The previous paragraph means that if you are overriding ``Form.clean()``, you 1294 should iterate through ``self.cleaned_data.items()``, possibly considering the 1295 ``_errors`` dictionary attribute on the form as well. In this way, you will 1296 already know which fields have passed thei individual validation requirements. 1214 1297 1215 1298 A simple example django/branches/unicode/scripts/rpm-install.sh
r4912 r5462 22 22 sed -e "/\.py[co]$/d" -e "s/\.py$/.py*/" DIRS FILES >INSTALLED_FILES 23 23 24 mkdir -p ${RPM_BUILD_ROOT}/%{_mandir}/man1/ 25 cp docs/man/* ${RPM_BUILD_ROOT}/%{_mandir}/man1/ 26 cat << EOF >> INSTALLED_FILES 27 %doc %{_mandir}/man1/*" 28 EOF django/branches/unicode/tests/regressiontests/serializers_regress/tests.py
r5419 r5462 289 289 obj = ComplexModel(field1='first',field2='second',field3='third') 290 290 obj.save() 291 291 292 292 # Serialize then deserialize the test database 293 293 serialized_data = serializers.serialize(format, [obj], indent=2, fields=('field1','field3')) 294 294 result = serializers.deserialize(format, serialized_data).next() 295 295 296 296 # Check that the deserialized object contains data in only the serialized fields. 297 297 self.assertEqual(result.object.field1, 'first') … … 305 305 obj = ComplexModel(field1='first',field2='second',field3='third') 306 306 obj.save() 307 307 308 308 # Serialize the test database to a stream 309 stream = StringIO() 309 stream = StringIO() 310 310 serializers.serialize(format, [obj], indent=2, stream=stream) 311 311 312 312 # Serialize normally for a comparison 313 313 string_data = serializers.serialize(format, [obj], indent=2) 314 314 315 315 # Check that the two are the same 316 self.assertEqual(string_data, stream. buffer())316 self.assertEqual(string_data, stream.getvalue()) 317 317 stream.close() 318 318 319 319 for format in serializers.get_serializer_formats(): 320 320 setattr(SerializerTests, 'test_'+format+'_serializer', curry(serializerTest, format)) 321 321 setattr(SerializerTests, 'test_'+format+'_serializer_fields', curry(fieldsTest, format)) 322 setattr(SerializerTests, 'test_'+format+'_serializer_stream', curry(fieldsTest, format)) 322 if format != 'python': 323 setattr(SerializerTests, 'test_'+format+'_serializer_stream', curry(streamTest, format))
