Django

Code

Changeset 993

Show
Ignore:
Timestamp:
10/23/05 05:18:03 (3 years ago)
Author:
hugo
Message:

i18n: merged to [992] from trunk

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/i18n/django/core/management.py

    r956 r993  
    300300        for sql in get_sql_create(core) + get_sql_create(auth) + get_sql_initial_data(core) + get_sql_initial_data(auth): 
    301301            cursor.execute(sql) 
    302         cursor.execute("INSERT INTO %s (domain, name) VALUES ('mysite.com', 'My Django site')" % core.Site._meta.db_table) 
     302        cursor.execute("INSERT INTO %s (domain, name) VALUES ('example.com', 'Example site')" % core.Site._meta.db_table) 
    303303    except Exception, e: 
    304304        sys.stderr.write("Error: The database couldn't be initialized.\n%s\n" % e) 
  • django/branches/i18n/django/core/meta/__init__.py

    r886 r993  
    13611361    id_list = args and args[0] or kwargs['id_list'] 
    13621362    assert id_list != [], "get_in_bulk() cannot be passed an empty list." 
    1363     kwargs['where'] = ["%s.id IN (%s)" % (opts.db_table, ",".join(map(str, id_list)))] 
     1363    kwargs['where'] = ["%s.%s IN (%s)" % (opts.db_table, opts.pk.column, ",".join(['%s'] * len(id_list)))] 
     1364    kwargs['params'] = id_list 
    13641365    obj_list = function_get_list(opts, klass, **kwargs) 
    1365     return dict([(o.id, o) for o in obj_list]) 
     1366    return dict([(getattr(o, opts.pk.column), o) for o in obj_list]) 
    13661367 
    13671368def function_get_latest(opts, klass, does_not_exist_exception, **kwargs): 
  • django/branches/i18n/django/core/template/loaders/app_directories.py

    r898 r993  
    22 
    33from django.conf.settings import INSTALLED_APPS, TEMPLATE_FILE_EXTENSION 
     4from django.core.exceptions import ImproperlyConfigured 
    45from django.core.template import TemplateDoesNotExist 
    56import os 
     
    910for app in INSTALLED_APPS: 
    1011    i = app.rfind('.') 
    11     m, a = app[:i], app[i+1:] 
    12     mod = getattr(__import__(m, '', '', [a]), a) 
     12    if i == -1: 
     13        m, a = app, None 
     14    else: 
     15        m, a = app[:i], app[i+1:] 
     16    try: 
     17        if a is None: 
     18            mod = __import__(m, '', '', []) 
     19        else: 
     20            mod = getattr(__import__(m, '', '', [a]), a) 
     21    except ImportError, e: 
     22        raise ImproperlyConfigured, 'ImportError %s: %s' % (app, e.args[0]) 
    1323    template_dir = os.path.join(os.path.dirname(mod.__file__), 'templates') 
    1424    if os.path.isdir(template_dir): 
  • django/branches/i18n/django/utils/dateformat.py

    r979 r993  
    1313 
    1414from django.utils.dates import MONTHS, MONTHS_AP, WEEKDAYS 
     15from django.utils.tzinfo import LocalTimezone 
    1516from calendar import isleap 
    16 import re 
     17import re, time 
    1718 
    1819re_formatchars = re.compile(r'(?<!\\)([aABdDfFgGhHiIjlLmMnNOPrsStTUwWyYzZ])') 
     
    4142    def A(self): 
    4243        "'AM' or 'PM'" 
    43         return self.a().upper() 
     44        if self.data.hour > 11: 
     45            return 'PM' 
     46        return 'AM' 
    4447 
    4548    def B(self): 
     
    101104    year_days = [None, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334] 
    102105 
    103     def __init__(self, d): 
    104         self.data = d 
     106    def __init__(self, dt): 
     107        # Accepts either a datetime or date object. 
     108        self.data = dt 
     109        self.timezone = getattr(dt, 'tzinfo', None) 
     110        if hasattr(self.data, 'hour') and not self.timezone: 
     111            self.timezone = LocalTimezone(dt) 
    105112 
    106113    def d(self): 
     
    120127        raise NotImplementedError 
    121128 
     129    def I(self): 
     130        "'1' if Daylight Savings Time, '0' otherwise." 
     131        if self.timezone.dst(self.data): 
     132            return '1' 
     133        else: 
     134            return '0' 
     135 
    122136    def j(self): 
    123137        "Day of the month without leading zeros; i.e. '1' to '31'" 
     
    150164    def O(self): 
    151165        "Difference to Greenwich time in hours; e.g. '+0200'" 
    152         raise NotImplementedError 
     166        tz = self.timezone.utcoffset(self.data) 
     167        return "%+03d%02d" % (tz.seconds // 3600, (tz.seconds // 60) % 60) 
    153168 
    154169    def r(self): 
    155170        "RFC 822 formatted date; e.g. 'Thu, 21 Dec 2000 16:01:07 +0200'" 
    156         raise NotImplementedError 
     171        return self.format('D, j M Y H:i:s O') 
    157172 
    158173    def S(self): 
     
    175190    def T(self): 
    176191        "Time zone of this machine; e.g. 'EST' or 'MDT'" 
    177         raise NotImplementedError 
     192        name = self.timezone.tzname(self.data) 
     193        if name is None: 
     194            name = self.format('O') 
     195        return name 
    178196 
    179197    def U(self): 
    180198        "Seconds since the Unix epoch (January 1 1970 00:00:00 GMT)" 
    181         raise NotImplementedError 
     199        off = self.timezone.utcoffset(self.data) 
     200        return int(time.mktime(self.data.timetuple())) + off.seconds * 60 
    182201 
    183202    def w(self): 
     
    230249        for timezones west of UTC is always negative, and for those east of UTC 
    231250        is always positive.""" 
    232         raise NotImplementedError 
     251        return self.timezone.utcoffset(self.data).seconds 
    233252 
    234253def format(value, format_string): 
  • django/branches/i18n/django/utils/timesince.py

    r3 r993  
    1 import time, math, datetime 
     1import datetime, math, time 
     2from django.utils.tzinfo import LocalTimezone 
    23 
    34def timesince(d, now=None): 
     
    78    Adapted from http://blog.natbat.co.uk/archive/2003/Jun/14/time_since 
    89    """ 
    9     original = time.mktime(d.timetuple()) 
    1010    chunks = ( 
    1111      (60 * 60 * 24 * 365, 'year'), 
     
    1515      (60, 'minute') 
    1616    ) 
    17     if not now: 
    18         now = time.time() 
    19     since = now - original 
     17    if now: 
     18        t = time.mktime(now) 
     19    else: 
     20        t = time.localtime() 
     21    if d.tzinfo: 
     22        tz = LocalTimezone() 
     23    else: 
     24        tz = None 
     25    now = datetime.datetime(t[0], t[1], t[2], t[3], t[4], t[5], tzinfo=tz) 
     26    delta = now - d 
     27    since = delta.days * 24 * 60 * 60 + delta.seconds 
    2028    # Crazy iteration syntax because we need i to be current index 
    2129    for i, (seconds, name) in zip(range(len(chunks)), chunks): 
  • django/branches/i18n/django/views/decorators/auth.py

    r3 r993  
     1def user_passes_test(view_func, test_func): 
     2    """ 
     3    Decorator for views that checks that the user passes the given test, 
     4    redirecting to the log-in page if necessary. The test should be a callable 
     5    that takes the user object and returns True if the user passes. 
     6    """ 
     7    from django.views.auth.login import redirect_to_login 
     8    def _checklogin(request, *args, **kwargs): 
     9        if test_func(request.user): 
     10            return view_func(request, *args, **kwargs) 
     11        return redirect_to_login(request.path) 
     12    return _checklogin 
     13 
    114def login_required(view_func): 
    215    """ 
     
    417    to the log-in page if necessary. 
    518    """ 
    6     from django.views.auth.login import redirect_to_login 
    7     def _checklogin(request, *args, **kwargs): 
    8         if request.user.is_anonymous(): 
    9             return redirect_to_login(request.path) 
    10         else: 
    11             return view_func(request, *args, **kwargs) 
    12     return _checklogin 
     19    return user_passes_test(lambda u: not u.is_anonymous()) 
  • django/branches/i18n/docs/templates.txt

    r979 r993  
    518518    N                 Month abbreviation in Associated Press  ``'Jan.'``, ``'Feb.'``, ``'March'``, ``'May'`` 
    519519                      style. Proprietary extension. 
    520     O                 Not implemented. 
     520    O                 Difference to Greenwich time in hours.  ``'+0200'`` 
    521521    P                 Time, in 12-hour hours, minutes and     ``'1 a.m.'``, ``'1:30 p.m.'``, ``'midnight'``, ``'noon'``, ``'12:30 p.m.'`` 
    522522                      'a.m.'/'p.m.', with minutes left off 
     
    524524                      strings 'midnight' and 'noon' if 
    525525                      appropriate. Proprietary extension. 
    526     r                 Not implemented. 
     526    r                 RFC 822 formatted date.                 ``'Thu, 21 Dec 2000 16:01:07 +0200'`` 
    527527    s                 Seconds, 2 digits with leading zeros.   ``'00'`` to ``'59'`` 
    528528    S                 English ordinal suffix for day of the   ``'st'``, ``'nd'``, ``'rd'`` or ``'th'`` 
    529529                      month, 2 characters. 
    530530    t                 Not implemented. 
    531     T                 Not implemented. 
     531    T                 Time zone of this machine.              ``'EST'``, ``'MDT'`` 
    532532    U                 Not implemented. 
    533533    w                 Day of the week, digits without         ``'0'`` (Sunday) to ``'6'`` (Saturday) 
     
    538538    Y                 Year, 4 digits.                         ``'1999'`` 
    539539    z                 Day of the year.                        ``0`` to ``365`` 
    540     Z                 Not implemented. 
     540    Z                 Time zone offset in seconds. The        ``-43200`` to ``43200`` 
     541                      offset for timezones west of UTC is 
     542                      always negative, and for those east of 
     543                      UTC is always positive. 
    541544    ================  ======================================  ===================== 
    542545 
     
    611614        {% ssi /home/html/ljworld.com/includes/right_generic.html parsed %} 
    612615 
     616    Note that if you use ``{% ssi %}``, you'll need to define 
     617    `ALLOWED_INCLUDE_ROOTS`_ in your Django settings, as a security measure. 
     618 
     619.. _ALLOWED_INCLUDE_ROOTS: http://www.djangoproject.com/documentation/settings/#allowed-include-roots 
     620 
    613621``templatetag`` 
    614622    Output one of the bits used to compose template tags. 
  • django/branches/i18n/tests/testapp/models/custom_pk.py

    r682 r993  
    5454>>> employees.get_list(last_name__exact='Jones') 
    5555[Dan Jones, Fran Jones] 
     56>>> employees.get_in_bulk(['ABC123', 'XYZ456']) 
     57{'XYZ456': Fran Jones, 'ABC123': Dan Jones} 
    5658 
    5759>>> b = businesses.Business(name='Sears') 
     
    6365>>> fran.get_business_list() 
    6466[Sears] 
     67>>> businesses.get_in_bulk(['Sears']) 
     68{'Sears': Sears} 
    6569"""