Ticket #7980: 7980_v1.diff

File 7980_v1.diff, 23.2 KB (added by Marc Garcia, 16 years ago)

Initial patch (partial)

  • conf/locale/ca/LC_MESSAGES/django.po

     
    501501msgid "Action"
    502502msgstr "Acció"
    503503
    504 #: contrib/admin/templates/admin/object_history.html:25
    505 msgid "DATE_WITH_TIME_FULL"
    506 msgstr "F j, Y, H:i "
    507 
    508504#: contrib/admin/templates/admin/object_history.html:35
    509505msgid ""
    510506"This object doesn't have a change history. It probably wasn't added via this "
     
    43784374msgid ", %(number)d %(type)s"
    43794375msgstr ", %(number)d %(type)s"
    43804376
    4381 #: utils/translation/trans_real.py:403
    4382 msgid "DATE_FORMAT"
    4383 msgstr "F j, Y"
    4384 
    43854377#: utils/translation/trans_real.py:404
    4386 msgid "DATETIME_FORMAT"
    4387 msgstr "F j, Y, H:i"
     4378msgid "LONG_DATE_FORMAT"
     4379msgstr "l, j \\de N \\de Y"
    43884380
    43894381#: utils/translation/trans_real.py:405
     4382msgid "SHORT_DATE_FORMAT"
     4383msgstr "d/m/Y"
     4384
     4385#: utils/translation/trans_real.py:406
     4386msgid "LONG_DATETIME_FORMAT"
     4387msgstr "l, j \\de N \\de Y, H:i"
     4388
     4389#: utils/translation/trans_real.py:407
     4390msgid "SHORT_DATETIME_FORMAT"
     4391msgstr "d/m/Y, H:i"
     4392
     4393#: utils/translation/trans_real.py:408
    43904394msgid "TIME_FORMAT"
    43914395msgstr "H:i"
    43924396
    4393 #: utils/translation/trans_real.py:421
     4397#: utils/translation/trans_real.py:409
    43944398msgid "YEAR_MONTH_FORMAT"
    4395 msgstr "j de/d' F del Y"
     4399msgstr "F \\de Y"
    43964400
    4397 #: utils/translation/trans_real.py:422
     4401#: utils/translation/trans_real.py:410
    43984402msgid "MONTH_DAY_FORMAT"
    4399 msgstr "j de/d' F del Y"
     4403msgstr "j \\de F"
    44004404
     4405#: utils/translation/trans_real.py:411
     4406msgid "FIRST_DAY_OF_WEEK"
     4407msgstr "1"
     4408
     4409#: utils/translation/trans_real.py:412
     4410msgid "DECIMAL_SEPARATOR"
     4411msgstr ","
     4412
     4413#: utils/translation/trans_real.py:413
     4414msgid "THOUSAND_SEPARATOR"
     4415msgstr "."
     4416
    44014417#: views/generic/create_update.py:43
    44024418#, python-format
    44034419msgid "The %(verbose_name)s was created successfully."
  • conf/locale/ca/LC_MESSAGES/djangojs.po

    Cannot display: file marked as a binary type.
    svn:mime-type = application/octet-stream
    Cannot display: file marked as a binary type.
    svn:mime-type = application/octet-stream
     
    5757msgid "S M T W T F S"
    5858msgstr "Dg Dl Dt Dc Dj Dv Ds"
    5959
     60#: contrib/admin/media/js/calendar.js:26
     61msgid "FIRST_DAY_OF_WEEK"
     62msgstr "1"
     63
    6064#: contrib/admin/media/js/admin/DateTimeShortcuts.js:47
    6165#: contrib/admin/media/js/admin/DateTimeShortcuts.js:81
    6266msgid "Now"
  • conf/locale/en/LC_MESSAGES/django.po

     
    474474msgid "Action"
    475475msgstr ""
    476476
    477 #: contrib/admin/templates/admin/object_history.html:25
    478 msgid "DATE_WITH_TIME_FULL"
    479 msgstr "N j, Y, P"
    480 
    481477#: contrib/admin/templates/admin/object_history.html:35
    482478msgid ""
    483479"This object doesn't have a change history. It probably wasn't added via this "
     
    37323728msgid ", %(number)d %(type)s"
    37333729msgstr ""
    37343730
    3735 #: utils/translation/trans_real.py:399
    3736 msgid "DATE_FORMAT"
     3731#: utils/translation/trans_real.py:405
     3732msgid "LONG_DATE_FORMAT"
    37373733msgstr "N j, Y"
    37383734
    3739 #: utils/translation/trans_real.py:400
    3740 msgid "DATETIME_FORMAT"
     3735#: utils/translation/trans_real.py:406
     3736msgid "SHORT_DATE_FORMAT"
     3737msgstr "m/d/Y"
     3738
     3739#: utils/translation/trans_real.py:407
     3740msgid "LONG_DATETIME_FORMAT"
    37413741msgstr "N j, Y, P"
    37423742
    3743 #: utils/translation/trans_real.py:401
     3743#: utils/translation/trans_real.py:408
     3744msgid "SHORT_DATETIME_FORMAT"
     3745msgstr "m/d/Y, P"
     3746
     3747#: utils/translation/trans_real.py:409
    37443748msgid "TIME_FORMAT"
    37453749msgstr "P"
    37463750
    3747 #: utils/translation/trans_real.py:417
     3751#: utils/translation/trans_real.py:410
    37483752msgid "YEAR_MONTH_FORMAT"
    37493753msgstr "F Y"
    37503754
    3751 #: utils/translation/trans_real.py:418
     3755#: utils/translation/trans_real.py:411
    37523756msgid "MONTH_DAY_FORMAT"
    37533757msgstr "F j"
    37543758
     3759#: utils/translation/trans_real.py:412
     3760msgid "FIRST_DAY_OF_WEEK"
     3761msgstr "0"
     3762
     3763#: utils/translation/trans_real.py:413
     3764msgid "DECIMAL_SEPARATOR"
     3765msgstr ","
     3766
     3767#: utils/translation/trans_real.py:414
     3768msgid "THOUSAND_SEPARATOR"
     3769msgstr "."
     3770
    37553771#: views/generic/create_update.py:43
    37563772#, python-format
    37573773msgid "The %(verbose_name)s was created successfully."
  • conf/locale/en/LC_MESSAGES/djangojs.po

    Cannot display: file marked as a binary type.
    svn:mime-type = application/octet-stream
    Cannot display: file marked as a binary type.
    svn:mime-type = application/octet-stream
     
    5656msgid "S M T W T F S"
    5757msgstr ""
    5858
     59#: contrib/admin/media/js/calendar.js:26
     60msgid "FIRST_DAY_OF_WEEK"
     61msgstr "0"
     62
    5963#: contrib/admin/media/js/dateparse.js:33
    6064msgid "Sunday Monday Tuesday Wednesday Thursday Friday Saturday"
    6165msgstr ""
  • conf/global_settings.py

     
    249249# (i.e. "/tmp" on *nix systems).
    250250FILE_UPLOAD_TEMP_DIR = None
    251251
    252 # Default formatting for date objects. See all available format strings here:
     252# Default formatting for long date objects. See all available format strings here:
    253253# http://www.djangoproject.com/documentation/templates/#now
    254 DATE_FORMAT = 'N j, Y'
     254LONG_DATE_FORMAT = 'N j, Y'
    255255
    256 # Default formatting for datetime objects. See all available format strings here:
     256# Default formatting for short date objects. See all available format strings here:
    257257# http://www.djangoproject.com/documentation/templates/#now
    258 DATETIME_FORMAT = 'N j, Y, P'
     258SHORT_DATE_FORMAT = 'm/d/Y'
    259259
     260# Default formatting for long datetime objects. See all available format strings here:
     261# http://www.djangoproject.com/documentation/templates/#now
     262LONG_DATETIME_FORMAT = 'N j, Y, P'
     263
     264# Default formatting for short datetime objects. See all available format strings here:
     265# http://www.djangoproject.com/documentation/templates/#now
     266SHORT_DATETIME_FORMAT = 'm/d/Y P'
     267
    260268# Default formatting for time objects. See all available format strings here:
    261269# http://www.djangoproject.com/documentation/templates/#now
    262270TIME_FORMAT = 'P'
     
    271279# http://www.djangoproject.com/documentation/templates/#now
    272280MONTH_DAY_FORMAT = 'F j'
    273281
     282# Default value for first day of week on calendars. 0 is Sunday, 1 is Monday...
     283FIRST_DAY_OF_WEEK = '0'
     284
     285# Default value used as decimal separator when formatting numbers.
     286DECIMAL_SEPARATOR = '.'
     287
     288# Default value used as thousand separator when formatting numbers.
     289THOUSAND_SEPARATOR = ','
     290
    274291# Do you want to manage transactions manually?
    275292# Hint: you really don't!
    276293TRANSACTIONS_MANAGED = False
  • utils/translation/trans_real.py

     
    44import os
    55import re
    66import sys
     7import decimal
     8import datetime
    79import gettext as gettext_module
    810from cStringIO import StringIO
    911
     12from django.utils import dateformat
    1013from django.utils.safestring import mark_safe, SafeData
    1114from django.utils.thread_support import currentThread
    1215
     
    391394
    392395    return settings.LANGUAGE_CODE
    393396
    394 def get_date_formats():
     397def get_formats():
    395398    """
    396399    Checks whether translation files provide a translation for some technical
    397     message ID to store date and time formats. If it doesn't contain one, the
     400    message ID to store date, time and number formats. If it doesn't contain one, the
    398401    formats provided in the settings will be used.
    399402    """
    400403    from django.conf import settings
    401     date_format = ugettext('DATE_FORMAT')
    402     datetime_format = ugettext('DATETIME_FORMAT')
    403     time_format = ugettext('TIME_FORMAT')
    404     if date_format == 'DATE_FORMAT':
    405         date_format = settings.DATE_FORMAT
    406     if datetime_format == 'DATETIME_FORMAT':
    407         datetime_format = settings.DATETIME_FORMAT
    408     if time_format == 'TIME_FORMAT':
    409         time_format = settings.TIME_FORMAT
    410     return date_format, datetime_format, time_format
     404    formats = {}
     405    formats['LONG_DATE_FORMAT'] = ugettext('LONG_DATE_FORMAT')
     406    formats['SHORT_DATE_FORMAT'] = ugettext('SHORT_DATE_FORMAT')
     407    formats['LONG_DATETIME_FORMAT'] = ugettext('LONG_DATETIME_FORMAT')
     408    formats['SHORT_DATETIME_FORMAT'] = ugettext('SHORT_DATETIME_FORMAT')
     409    formats['TIME_FORMAT'] = ugettext('TIME_FORMAT')
     410    formats['YEAR_MONTH_FORMAT'] = ugettext('YEAR_MONTH_FORMAT')
     411    formats['MONTH_DAY_FORMAT'] = ugettext('MONTH_DAY_FORMAT')
     412    formats['FIRST_DAY_OF_WEEK'] = ugettext('FIRST_DAY_OF_WEEK')
     413    formats['DECIMAL_SEPARATOR'] = ugettext('DECIMAL_SEPARATOR')
     414    formats['THOUSAND_SEPARATOR'] = ugettext('THOUSAND_SEPARATOR')
     415   
     416    for format_name, format_value in formats.iteritems():
     417        if format_name == format_value:
     418            formats[format_name] = getattr(settings, format_name)
    411419
    412 def get_partial_date_formats():
     420    return formats
     421
     422def i18ize(value):
    413423    """
    414     Checks whether translation files provide a translation for some technical
    415     message ID to store partial date formats. If it doesn't contain one, the
    416     formats provided in the settings will be used.
     424    Converts a date/time or decimal number to a string, using the format defined
     425    for current locale.
    417426    """
    418     from django.conf import settings
    419     year_month_format = ugettext('YEAR_MONTH_FORMAT')
    420     month_day_format = ugettext('MONTH_DAY_FORMAT')
    421     if year_month_format == 'YEAR_MONTH_FORMAT':
    422         year_month_format = settings.YEAR_MONTH_FORMAT
    423     if month_day_format == 'MONTH_DAY_FORMAT':
    424         month_day_format = settings.MONTH_DAY_FORMAT
    425     return year_month_format, month_day_format
     427    formats = get_formats()
     428    if isinstance(value, decimal.Decimal):
     429        return str(value).replace('.', formats['DECIMAL_SEPARATOR'])
     430    elif isinstance(value, datetime.date):
     431        return dateformat.format(value, formats['LONG_DATE_FORMAT'])
     432    elif isinstance(value, datetime.datetime):
     433        return dateformat.format(value, formats['LONG_DATETIME_FORMAT'])
     434    else:
     435        return value
    426436
    427437dot_re = re.compile(r'\S')
    428438def blankout(src, char):
  • utils/translation/__init__.py

     
    66
    77__all__ = ['gettext', 'gettext_noop', 'gettext_lazy', 'ngettext',
    88        'ngettext_lazy', 'string_concat', 'activate', 'deactivate',
    9         'get_language', 'get_language_bidi', 'get_date_formats',
    10         'get_partial_date_formats', 'check_for_language', 'to_locale',
    11         'get_language_from_request', 'templatize', 'ugettext',
    12         'ungettext', 'deactivate_all']
     9        'get_language', 'get_language_bidi', 'get_formats', 'i18ize',
     10        'check_for_language', 'to_locale', 'get_language_from_request',
     11        'templatize', 'ugettext', 'ungettext', 'deactivate_all']
    1312
    1413# Here be dragons, so a short explanation of the logic won't hurt:
    1514# We are trying to solve two problems: (1) access settings, in particular
     
    8180def get_language_bidi():
    8281    return real_get_language_bidi()
    8382
    84 def get_date_formats():
    85     return real_get_date_formats()
     83def get_formats():
     84    return real_get_formats()
    8685
    87 def get_partial_date_formats():
    88     return real_get_partial_date_formats()
     86def i18ize(value):
     87    return real_i18ize(value)
    8988
    9089def check_for_language(lang_code):
    9190    return real_check_for_language(lang_code)
  • utils/translation/trans_null.py

     
    1818deactivate = deactivate_all = lambda: None
    1919get_language = lambda: settings.LANGUAGE_CODE
    2020get_language_bidi = lambda: settings.LANGUAGE_CODE in settings.LANGUAGES_BIDI
    21 get_date_formats = lambda: (settings.DATE_FORMAT, settings.DATETIME_FORMAT, settings.TIME_FORMAT)
    22 get_partial_date_formats = lambda: (settings.YEAR_MONTH_FORMAT, settings.MONTH_DAY_FORMAT)
    2321check_for_language = lambda x: True
    2422
    2523TECHNICAL_ID_MAP = {
     
    5149
    5250def get_language_from_request(request):
    5351    return settings.LANGUAGE_CODE
     52
     53def get_formats():
     54    formats = ('LONG_DATE_FORMAT', 'SHORT_DATE_FORMAT', 'LONG_DATETIME_FORMAT',
     55        'SHORT_DATETIME_FORMAT', 'TIME_FORMAT', 'YEAR_MONTH_FORMAT', 'MONTH_DAY_FORMAT',
     56        'FIRST_DAY_OF_WEEK', 'DECIMAL_SEPARATOR', 'THOUSAND_SEPARATOR')
     57    result = {}
     58    for format in formats:
     59        result[format] = getattr(settings, format)
     60    return result
     61
     62def i18ize(value):
     63    return value
  • contrib/admin/media/js/calendar.js

     
    2525var CalendarNamespace = {
    2626    monthsOfYear: gettext('January February March April May June July August September October November December').split(' '),
    2727    daysOfWeek: gettext('S M T W T F S').split(' '),
     28    firstDayOfWeek: parseInt(gettext('FIRST_DAY_OF_WEEK').replace('FIRST_DAY_OF_WEEK', '0')),
    2829    isLeapYear: function(year) {
    2930        return (((year % 4)==0) && ((year % 100)!=0) || ((year % 400)==0));
    3031    },
     
    5657        // Draw days-of-week header
    5758        var tableRow = quickElement('tr', tableBody);
    5859        for (var i = 0; i < 7; i++) {
    59             quickElement('th', tableRow, CalendarNamespace.daysOfWeek[i]);
     60            quickElement('th', tableRow, CalendarNamespace.daysOfWeek[(i + CalendarNamespace.firstDayOfWeek) % 7]);
    6061        }
    6162
    6263        var startingPos = new Date(year, month-1, 1).getDay();
  • contrib/admin/templatetags/admin_list.py

     
    77from django.utils.html import escape, conditional_escape
    88from django.utils.text import capfirst
    99from django.utils.safestring import mark_safe
    10 from django.utils.translation import get_date_formats, get_partial_date_formats, ugettext as _
     10from django.utils.translation import get_formats, ugettext as _
    1111from django.utils.encoding import smart_unicode, smart_str, force_unicode
    1212from django.template import Library
    1313import datetime
     
    153153        else:
    154154            field_val = getattr(result, f.attname)
    155155
     156            formats = get_formats()
    156157            if isinstance(f.rel, models.ManyToOneRel):
    157158                if field_val is not None:
    158159                    result_repr = escape(getattr(result, f.name))
     
    161162            # Dates and times are special: They're formatted in a certain way.
    162163            elif isinstance(f, models.DateField) or isinstance(f, models.TimeField):
    163164                if field_val:
    164                     (date_format, datetime_format, time_format) = get_date_formats()
    165165                    if isinstance(f, models.DateTimeField):
    166                         result_repr = capfirst(dateformat.format(field_val, datetime_format))
     166                        result_repr = capfirst(dateformat.format(field_val, formats['LONG_DATETIME_FORMAT']))
    167167                    elif isinstance(f, models.TimeField):
    168                         result_repr = capfirst(dateformat.time_format(field_val, time_format))
     168                        result_repr = capfirst(dateformat.time_format(field_val, formats['TIME_FORMAT']))
    169169                    else:
    170                         result_repr = capfirst(dateformat.format(field_val, date_format))
     170                        result_repr = capfirst(dateformat.format(field_val, formats['LONG_DATE_FORMAT']))
    171171                else:
    172172                    result_repr = EMPTY_CHANGELIST_VALUE
    173173                row_class = ' class="nowrap"'
     
    177177            # DecimalFields are special: Zero-pad the decimals.
    178178            elif isinstance(f, models.DecimalField):
    179179                if field_val is not None:
    180                     result_repr = ('%%.%sf' % f.decimal_places) % field_val
     180                    result_repr = (('%%.%sf' % f.decimal_places) % field_val).replace('.', formats['DECIMAL_SEPARATOR'])
    181181                else:
    182182                    result_repr = EMPTY_CHANGELIST_VALUE
    183183            # Fields with choices are special: Use the representation
     
    221221        year_lookup = cl.params.get(year_field)
    222222        month_lookup = cl.params.get(month_field)
    223223        day_lookup = cl.params.get(day_field)
    224         year_month_format, month_day_format = get_partial_date_formats()
     224        formats = get_formats()
    225225
    226226        link = lambda d: mark_safe(cl.get_query_string(d, [field_generic]))
    227227
     
    231231                'show': True,
    232232                'back': {
    233233                    'link': link({year_field: year_lookup, month_field: month_lookup}),
    234                     'title': dateformat.format(day, year_month_format)
     234                    'title': dateformat.format(day, formats['YEAR_MONTH_FORMAT'])
    235235                },
    236                 'choices': [{'title': dateformat.format(day, month_day_format)}]
     236                'choices': [{'title': dateformat.format(day, formats['MONTH_DAY_FORMAT'])}]
    237237            }
    238238        elif year_lookup and month_lookup:
    239239            days = cl.query_set.filter(**{year_field: year_lookup, month_field: month_lookup}).dates(field_name, 'day')
     
    245245                },
    246246                'choices': [{
    247247                    'link': link({year_field: year_lookup, month_field: month_lookup, day_field: day.day}),
    248                     'title': dateformat.format(day, month_day_format)
     248                    'title': dateformat.format(day, formats['MONTH_DAY_FORMAT'])
    249249                } for day in days]
    250250            }
    251251        elif year_lookup:
     
    258258                },
    259259                'choices': [{
    260260                    'link': link({year_field: year_lookup, month_field: month.month}),
    261                     'title': dateformat.format(month, year_month_format)
     261                    'title': dateformat.format(month, formats['YEAR_MONTH_FORMAT'])
    262262                } for month in months]
    263263            }
    264264        else:
  • contrib/admin/templates/admin/object_history.html

     
    2121        <tbody>
    2222        {% for action in action_list %}
    2323        <tr>
    24             <th scope="row">{{ action.action_time|date:_("DATE_WITH_TIME_FULL") }}</th>
     24            <th scope="row">{{ action.action_time }}</th>
    2525            <td>{{ action.user.username }}{% if action.user.first_name %} ({{ action.user.first_name }} {{ action.user.last_name }}){% endif %}</td>
    2626            <td>{{ action.change_message }}</td>
    2727        </tr>
  • contrib/databrowse/datastructures.py

     
    66from django.db import models
    77from django.utils import dateformat
    88from django.utils.text import capfirst
    9 from django.utils.translation import get_date_formats
     9from django.utils.translation import get_formats
    1010from django.utils.encoding import smart_unicode, smart_str, iri_to_uri
    1111from django.utils.safestring import mark_safe
    1212from django.db.models.query import QuerySet
     
    156156            objs = dict(self.field.choices).get(self.raw_value, EMPTY_VALUE)
    157157        elif isinstance(self.field, models.DateField) or isinstance(self.field, models.TimeField):
    158158            if self.raw_value:
    159                 date_format, datetime_format, time_format = get_date_formats()
     159                formats = get_formats()
    160160                if isinstance(self.field, models.DateTimeField):
    161                     objs = capfirst(dateformat.format(self.raw_value, datetime_format))
     161                    objs = capfirst(dateformat.format(self.raw_value, formats['DATETIME_FORMAT']))
    162162                elif isinstance(self.field, models.TimeField):
    163                     objs = capfirst(dateformat.time_format(self.raw_value, time_format))
     163                    objs = capfirst(dateformat.time_format(self.raw_value, formats['TIME_FORMAT']))
    164164                else:
    165                     objs = capfirst(dateformat.format(self.raw_value, date_format))
     165                    objs = capfirst(dateformat.format(self.raw_value, formats['DATE_FORMAT']))
    166166            else:
    167167                objs = EMPTY_VALUE
    168168        elif isinstance(self.field, models.BooleanField) or isinstance(self.field, models.NullBooleanField):
  • template/__init__.py

     
    5656from django.utils.functional import curry, Promise
    5757from django.utils.text import smart_split
    5858from django.utils.encoding import smart_unicode, force_unicode
    59 from django.utils.translation import ugettext as _
     59from django.utils.translation import i18ize, ugettext as _
    6060from django.utils.safestring import SafeData, EscapeData, mark_safe, mark_for_escaping
    6161from django.utils.html import escape
    6262
     
    782782
    783783    def render(self, context):
    784784        try:
    785             output = force_unicode(self.filter_expression.resolve(context))
     785            value = self.filter_expression.resolve(context)
     786            i18n_value = i18ize(value)
     787            output = force_unicode(i18n_value)
    786788        except UnicodeDecodeError:
    787789            # Unicode conversion can fail sometimes for reasons out of our
    788790            # control (e.g. exception rendering). In that case, we fail quietly.
  • template/debug.py

     
     1import decimal, datetime
    12from django.template import Lexer, Parser, tag_re, NodeList, VariableNode, TemplateSyntaxError
    23from django.utils.encoding import force_unicode
    34from django.utils.html import escape
     
    23from django.utils.safestring import SafeData, EscapeData
     4from django.utils.translation import i18ize
    35
     
    8486class DebugVariableNode(VariableNode):
    8587    def render(self, context):
    8688        try:
    87             output = force_unicode(self.filter_expression.resolve(context))
     89            value = self.filter_expression.resolve(context)
     90            i18n_value = i18ize(value)
     91            output = force_unicode(i18n_value)
    8892        except TemplateSyntaxError, e:
    8993            if not hasattr(e, 'source'):
    9094                e.source = self.source
Back to Top