Django

Code

Changeset 5462

Show
Ignore:
Timestamp:
06/11/07 09:51:26 (1 year ago)
Author:
mtredinnick
Message:

unicode: Merged changes from trunk up to [5460].

Files:

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  
    7474    Ian Clelland <clelland@gmail.com> 
    7575    crankycoder@gmail.com 
     76    Pete Crosier <pete.crosier@gmail.com> 
    7677    Matt Croydon <http://www.postneo.com/> 
    7778    flavio.curella@gmail.com 
     
    132133    Antti Kaihola <http://akaihola.blogspot.com/> 
    133134    Ben Dean Kawamura <ben.dean.kawamura@gmail.com> 
     135    ian.g.kelly@gmail.com 
    134136    Garth Kidd <http://www.deadlybloodyserious.com/> 
    135137    kilian <kilian.cavalotti@lip6.fr> 
     
    172174    mmarshall 
    173175    Eric Moritz <http://eric.themoritzfamily.com/> 
     176    mrmachine <real.human@mrmachine.net> 
    174177    Robin Munn <http://www.geekforgod.com/> 
    175178    Robert Myers <myer0052@gmail.com> 
     
    237240    Dan Watson <http://theidioteque.net/> 
    238241    Chris Wesseling <Chris.Wesseling@cwi.nl> 
     242    James Wheare <django@sparemint.com> 
    239243    charly.wilhelm@gmail.com 
    240244    Rachel Willmer <http://www.willmer.com/kb/> 
  • django/branches/unicode/django/conf/global_settings.py

    r5381 r5462  
    245245# The User-Agent string to use when checking for URL validity through the 
    246246# isExistingURL validator. 
    247 URL_VALIDATOR_USER_AGENT = "Django/0.96pre (http://www.djangoproject.com)" 
     247from django import get_version 
     248URL_VALIDATOR_USER_AGENT = "Django/%s (http://www.djangoproject.com)" % get_version() 
    248249 
    249250############## 
  • django/branches/unicode/django/conf/locale/nl/LC_MESSAGES/django.po

    r4530 r5462  
    22032203 
    22042204#: utils/timesince.py:16 
     2205# In the timesince context it is stilistically wrong to use the plural for hour in Dutch. 
    22052206msgid "hour" 
    22062207msgid_plural "hours" 
    22072208msgstr[0] "uur" 
    2208 msgstr[1] "uren
     2209msgstr[1] "uur
    22092210 
    22102211#: utils/timesince.py:17 
  • django/branches/unicode/django/core/management.py

    r5381 r5462  
    44import django 
    55from django.core.exceptions import ImproperlyConfigured 
    6 import os, re, shutil, sys, textwrap 
    76from optparse import OptionParser 
    87from django.utils import termcolors 
     8import os, re, shutil, sys, textwrap 
    99 
    1010# For Python 2.3 
    1111if not hasattr(__builtins__, 'set'): 
    1212    from sets import Set as set 
     13 
     14# For backwards compatibility: get_version() used to be in this module. 
     15get_version = django.get_version 
    1316 
    1417MODULE_TEMPLATE = '''    {%% if perms.%(app)s.%(addperm)s or perms.%(app)s.%(changeperm)s %%} 
     
    9396# field as the field to which it points. 
    9497get_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 VERSION 
    99     v = '.'.join([str(i) for i in VERSION[:-1]]) 
    100     if VERSION[-1]: 
    101         v += '-' + VERSION[-1] 
    102     return v 
    10398 
    10499def get_sql_create(app): 
  • django/branches/unicode/django/db/backends/postgresql/base.py

    r5310 r5462  
    240240    output = [] 
    241241    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. 
    242245        for f in model._meta.fields: 
    243246            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;" % \ 
    245248                    (style.SQL_KEYWORD('SELECT'), 
    246249                    style.SQL_FIELD(quote_name('%s_%s_seq' % (model._meta.db_table, f.column))), 
    247                     style.SQL_KEYWORD('SELECT'), 
    248250                    style.SQL_FIELD(quote_name(f.column)), 
     251                    style.SQL_FIELD(quote_name(f.column)), 
     252                    style.SQL_KEYWORD('IS NOT'), 
    249253                    style.SQL_KEYWORD('FROM'), 
    250254                    style.SQL_TABLE(quote_name(model._meta.db_table)))) 
    251255                break # Only one AutoField is allowed per model, so don't bother continuing. 
    252256        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;" % \ 
    254258                (style.SQL_KEYWORD('SELECT'), 
    255259                style.SQL_FIELD(quote_name('%s_id_seq' % f.m2m_db_table())), 
    256                 style.SQL_KEYWORD('SELECT'), 
    257260                style.SQL_FIELD(quote_name('id')), 
     261                style.SQL_FIELD(quote_name('id')), 
     262                style.SQL_KEYWORD('IS NOT'), 
    258263                style.SQL_KEYWORD('FROM'), 
    259264                style.SQL_TABLE(f.m2m_db_table()))) 
  • django/branches/unicode/django/db/backends/postgresql_psycopg2/base.py

    r5214 r5462  
    181181    output = [] 
    182182    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. 
    183186        for f in model._meta.fields: 
    184187            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;" % \ 
    186189                    (style.SQL_KEYWORD('SELECT'), 
    187190                    style.SQL_FIELD(quote_name('%s_%s_seq' % (model._meta.db_table, f.column))), 
    188                     style.SQL_KEYWORD('SELECT'), 
    189191                    style.SQL_FIELD(quote_name(f.column)), 
     192                    style.SQL_FIELD(quote_name(f.column)), 
     193                    style.SQL_KEYWORD('IS NOT'), 
    190194                    style.SQL_KEYWORD('FROM'), 
    191195                    style.SQL_TABLE(quote_name(model._meta.db_table)))) 
    192196                break # Only one AutoField is allowed per model, so don't bother continuing. 
    193197        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;" % \ 
    195199                (style.SQL_KEYWORD('SELECT'), 
    196200                style.SQL_FIELD(quote_name('%s_id_seq' % f.m2m_db_table())), 
    197                 style.SQL_KEYWORD('SELECT'), 
    198201                style.SQL_FIELD(quote_name('id')), 
     202                style.SQL_FIELD(quote_name('id')), 
     203                style.SQL_KEYWORD('IS NOT'), 
    199204                style.SQL_KEYWORD('FROM'), 
    200205                style.SQL_TABLE(f.m2m_db_table()))) 
  • django/branches/unicode/django/db/backends/util.py

    r5400 r5462  
    9999 
    100100def typecast_decimal(s): 
    101     if s is None
     101    if s is None or s == ''
    102102        return None 
    103103    return decimal.Decimal(s) 
  • django/branches/unicode/django/__init__.py

    r4914 r5462  
    11VERSION = (0, 97, 'pre') 
     2 
     3def 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  
    88import sys 
    99import re 
     10 
     11if 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 
    1018 
    1119register = Library() 
     
    105113        len_values = len(values) 
    106114        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) 
    112116        unpack = len(self.loopvars) > 1 
    113117        for i, item in enumerate(values): 
  • django/branches/unicode/django/views/debug.py

    r5316 r5462  
    44from django.http import HttpResponseServerError, HttpResponseNotFound 
    55from django.utils.encoding import smart_unicode 
    6 import os, re 
     6import os, re, sys 
    77 
    88HIDDEN_SETTINGS = re.compile('SECRET|PASSWORD|PROFANITIES_LIST') 
     
    133133        'request_protocol': request.is_secure() and "https" or "http", 
    134134        'settings': get_safe_settings(), 
     135        'sys_executable' : sys.executable, 
     136        'sys_version_info' : '%d.%d.%d' % sys.version_info[0:3], 
    135137        'template_info': template_info, 
    136138        'template_does_not_exist': template_does_not_exist, 
     
    347349      <td>{{ lastframe.filename|escape }} in {{ lastframe.function|escape }}, line {{ lastframe.lineno }}</td> 
    348350    </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> 
    349359  </table> 
    350360</div> 
  • django/branches/unicode/docs/authentication.txt

    r5126 r5462  
    731731------------------- 
    732732 
    733 Three basic permissions -- add, create and delete -- are automatically created 
     733Three basic permissions -- add, change and delete -- are automatically created 
    734734for each Django model that has a ``class Admin`` set. Behind the scenes, these 
    735735permissions are added to the ``auth_permission`` database table when you run 
  • django/branches/unicode/docs/db-api.txt

    r5444 r5462  
    389389underlying SQL statement, and the whole thing is enclosed in a ``NOT()``. 
    390390 
    391 This example excludes all entries whose ``pub_date`` is the current date/time 
     391This example excludes all entries whose ``pub_date`` is later than 2005-1-3 
    392392AND whose ``headline`` is "Hello":: 
    393393 
     
    399399    WHERE NOT (pub_date > '2005-1-3' AND headline = 'Hello') 
    400400 
    401 This example excludes all entries whose ``pub_date`` is the current date/time 
    402 OR whose ``headline`` is "Hello":: 
     401This example excludes all entries whose ``pub_date`` is later than 2005-1-3 
     402AND whose headline is NOT "Hello":: 
    403403 
    404404    Entry.objects.exclude(pub_date__gt=datetime.date(2005, 1, 3)).exclude(headline='Hello') 
  • django/branches/unicode/docs/model-api.txt

    r5444 r5462  
    447447 
    448448The admin represents this as an ``<input type="text">`` (a single-line input). 
     449 
     450``URLField`` takes an optional argument, ``maxlength``, the maximum length (in 
     451characters) of the field. The maxlength is enforced at the database level and 
     452in Django's validation. If you don't specify ``maxlength``, a default of 200 
     453is used. 
    449454 
    450455``USStateField`` 
  • django/branches/unicode/docs/newforms.txt

    r5444 r5462  
    303303full details on each field's behavior in this case, see the "Empty value" note 
    304304for each field in the "Built-in ``Field`` classes" section below. 
     305 
     306You can write code to perform validation for particular form fields (based on 
     307their name) or for the form as a whole (considering combinations of various 
     308fields). More information about this is in the `Custom form and field 
     309validation`_ section, below. 
    305310 
    306311Behavior of unbound forms 
     
    12121217mentioned above (``required``, ``label``, ``initial``, ``widget``, 
    12131218``help_text``). 
     1219 
     1220Custom form and field validation 
     1221--------------------------------- 
     1222 
     1223Form validation happens when the data is cleaned. If you want to customise 
     1224this process, there are various places you can change, each one serving a 
     1225different purpose. Thee types of cleaning methods are run during form 
     1226processing. These are normally executed when you call the ``is_valid()`` 
     1227method on a form. There are other things that can kick of cleaning and 
     1228validation (accessing the ``errors`` attribute or calling ``full_clean()`` 
     1229directly), but normally they won't be needed. 
     1230 
     1231In general, any cleaning method can raise ``ValidationError`` if there is a 
     1232problem with the data it is processing, passing the relevant error message to 
     1233the ``ValidationError`` constructor. If no ``ValidationError`` is raised, the 
     1234method should return the cleaned (normalised) data as a Python object. 
     1235 
     1236If you detect multiple errors during a cleaning method and wish to signal all 
     1237of them to the form submittor, it is possible to pass a list of errors to the 
     1238``ValidationError`` constructor. 
     1239 
     1240The 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 
     1278These methods are run in the order given above, one field at a time.  That is, 
     1279for each field in the form (in the order they are declared in the form 
     1280definition), the ``Field.clean()`` method (or it's override) is run, then 
     1281``clean_<fieldname>()``. Finally, once those two methods are run for every 
     1282field, the ``Form.clean()`` method, or it's override, is executed. 
     1283 
     1284As mentioned above, any of these methods can raise a ``ValidationError``. For 
     1285any field, if the ``Field.clean()`` method raises a ``ValidationError``, any 
     1286field-specific cleaning method is not called. However, the cleaning methods 
     1287for all remaining fields are still executed. 
     1288 
     1289The ``clean()`` method for the ``Form`` class or subclass is always run. If 
     1290that method raises a ``ValidationError``, ``cleaned_data`` will be an empty 
     1291dictionary. 
     1292 
     1293The previous paragraph means that if you are overriding ``Form.clean()``, you 
     1294should iterate through ``self.cleaned_data.items()``, possibly considering the 
     1295``_errors`` dictionary attribute on the form as well. In this way, you will 
     1296already know which fields have passed thei individual validation requirements. 
    12141297 
    12151298A simple example 
  • django/branches/unicode/scripts/rpm-install.sh

    r4912 r5462  
    2222sed -e "/\.py[co]$/d" -e "s/\.py$/.py*/" DIRS FILES >INSTALLED_FILES 
    2323 
     24mkdir -p ${RPM_BUILD_ROOT}/%{_mandir}/man1/ 
     25cp docs/man/* ${RPM_BUILD_ROOT}/%{_mandir}/man1/ 
     26cat << EOF >> INSTALLED_FILES 
     27%doc %{_mandir}/man1/*" 
     28EOF 
  • django/branches/unicode/tests/regressiontests/serializers_regress/tests.py

    r5419 r5462  
    289289    obj = ComplexModel(field1='first',field2='second',field3='third') 
    290290    obj.save() 
    291      
     291 
    292292    # Serialize then deserialize the test database 
    293293    serialized_data = serializers.serialize(format, [obj], indent=2, fields=('field1','field3')) 
    294294    result = serializers.deserialize(format, serialized_data).next() 
    295      
     295 
    296296    # Check that the deserialized object contains data in only the serialized fields. 
    297297    self.assertEqual(result.object.field1, 'first') 
     
    305305    obj = ComplexModel(field1='first',field2='second',field3='third') 
    306306    obj.save() 
    307      
     307 
    308308    # Serialize the test database to a stream 
    309     stream = StringIO()     
     309    stream = StringIO() 
    310310    serializers.serialize(format, [obj], indent=2, stream=stream) 
    311      
     311 
    312312    # Serialize normally for a comparison 
    313313    string_data = serializers.serialize(format, [obj], indent=2) 
    314314 
    315315    # Check that the two are the same 
    316     self.assertEqual(string_data, stream.buffer()) 
     316    self.assertEqual(string_data, stream.getvalue()) 
    317317    stream.close() 
    318      
     318 
    319319for format in serializers.get_serializer_formats(): 
    320320    setattr(SerializerTests, 'test_'+format+'_serializer', curry(serializerTest, format)) 
    321321    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))