Changeset 993
- Timestamp:
- 10/23/05 05:18:03 (3 years ago)
- Files:
-
- django/branches/i18n/django/core/management.py (modified) (1 diff)
- django/branches/i18n/django/core/meta/__init__.py (modified) (1 diff)
- django/branches/i18n/django/core/template/loaders/app_directories.py (modified) (2 diffs)
- django/branches/i18n/django/utils/dateformat.py (modified) (7 diffs)
- django/branches/i18n/django/utils/timesince.py (modified) (3 diffs)
- django/branches/i18n/django/utils/tzinfo.py (added)
- django/branches/i18n/django/views/decorators/auth.py (modified) (2 diffs)
- django/branches/i18n/docs/authentication.txt (added)
- django/branches/i18n/docs/templates.txt (modified) (4 diffs)
- django/branches/i18n/tests/othertests/dateformat.py (added)
- django/branches/i18n/tests/testapp/models/custom_pk.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/i18n/django/core/management.py
r956 r993 300 300 for sql in get_sql_create(core) + get_sql_create(auth) + get_sql_initial_data(core) + get_sql_initial_data(auth): 301 301 cursor.execute(sql) 302 cursor.execute("INSERT INTO %s (domain, name) VALUES (' mysite.com', 'My Djangosite')" % core.Site._meta.db_table)302 cursor.execute("INSERT INTO %s (domain, name) VALUES ('example.com', 'Example site')" % core.Site._meta.db_table) 303 303 except Exception, e: 304 304 sys.stderr.write("Error: The database couldn't be initialized.\n%s\n" % e) django/branches/i18n/django/core/meta/__init__.py
r886 r993 1361 1361 id_list = args and args[0] or kwargs['id_list'] 1362 1362 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 1364 1365 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]) 1366 1367 1367 1368 def function_get_latest(opts, klass, does_not_exist_exception, **kwargs): django/branches/i18n/django/core/template/loaders/app_directories.py
r898 r993 2 2 3 3 from django.conf.settings import INSTALLED_APPS, TEMPLATE_FILE_EXTENSION 4 from django.core.exceptions import ImproperlyConfigured 4 5 from django.core.template import TemplateDoesNotExist 5 6 import os … … 9 10 for app in INSTALLED_APPS: 10 11 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]) 13 23 template_dir = os.path.join(os.path.dirname(mod.__file__), 'templates') 14 24 if os.path.isdir(template_dir): django/branches/i18n/django/utils/dateformat.py
r979 r993 13 13 14 14 from django.utils.dates import MONTHS, MONTHS_AP, WEEKDAYS 15 from django.utils.tzinfo import LocalTimezone 15 16 from calendar import isleap 16 import re 17 import re, time 17 18 18 19 re_formatchars = re.compile(r'(?<!\\)([aABdDfFgGhHiIjlLmMnNOPrsStTUwWyYzZ])') … … 41 42 def A(self): 42 43 "'AM' or 'PM'" 43 return self.a().upper() 44 if self.data.hour > 11: 45 return 'PM' 46 return 'AM' 44 47 45 48 def B(self): … … 101 104 year_days = [None, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334] 102 105 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) 105 112 106 113 def d(self): … … 120 127 raise NotImplementedError 121 128 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 122 136 def j(self): 123 137 "Day of the month without leading zeros; i.e. '1' to '31'" … … 150 164 def O(self): 151 165 "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) 153 168 154 169 def r(self): 155 170 "RFC 822 formatted date; e.g. 'Thu, 21 Dec 2000 16:01:07 +0200'" 156 r aise NotImplementedError171 return self.format('D, j M Y H:i:s O') 157 172 158 173 def S(self): … … 175 190 def T(self): 176 191 "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 178 196 179 197 def U(self): 180 198 "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 182 201 183 202 def w(self): … … 230 249 for timezones west of UTC is always negative, and for those east of UTC 231 250 is always positive.""" 232 r aise NotImplementedError251 return self.timezone.utcoffset(self.data).seconds 233 252 234 253 def format(value, format_string): django/branches/i18n/django/utils/timesince.py
r3 r993 1 import time, math, datetime 1 import datetime, math, time 2 from django.utils.tzinfo import LocalTimezone 2 3 3 4 def timesince(d, now=None): … … 7 8 Adapted from http://blog.natbat.co.uk/archive/2003/Jun/14/time_since 8 9 """ 9 original = time.mktime(d.timetuple())10 10 chunks = ( 11 11 (60 * 60 * 24 * 365, 'year'), … … 15 15 (60, 'minute') 16 16 ) 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 20 28 # Crazy iteration syntax because we need i to be current index 21 29 for i, (seconds, name) in zip(range(len(chunks)), chunks): django/branches/i18n/django/views/decorators/auth.py
r3 r993 1 def 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 1 14 def login_required(view_func): 2 15 """ … … 4 17 to the log-in page if necessary. 5 18 """ 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 518 518 N Month abbreviation in Associated Press ``'Jan.'``, ``'Feb.'``, ``'March'``, ``'May'`` 519 519 style. Proprietary extension. 520 O Not implemented.520 O Difference to Greenwich time in hours. ``'+0200'`` 521 521 P Time, in 12-hour hours, minutes and ``'1 a.m.'``, ``'1:30 p.m.'``, ``'midnight'``, ``'noon'``, ``'12:30 p.m.'`` 522 522 'a.m.'/'p.m.', with minutes left off … … 524 524 strings 'midnight' and 'noon' if 525 525 appropriate. Proprietary extension. 526 r Not implemented.526 r RFC 822 formatted date. ``'Thu, 21 Dec 2000 16:01:07 +0200'`` 527 527 s Seconds, 2 digits with leading zeros. ``'00'`` to ``'59'`` 528 528 S English ordinal suffix for day of the ``'st'``, ``'nd'``, ``'rd'`` or ``'th'`` 529 529 month, 2 characters. 530 530 t Not implemented. 531 T Not implemented.531 T Time zone of this machine. ``'EST'``, ``'MDT'`` 532 532 U Not implemented. 533 533 w Day of the week, digits without ``'0'`` (Sunday) to ``'6'`` (Saturday) … … 538 538 Y Year, 4 digits. ``'1999'`` 539 539 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. 541 544 ================ ====================================== ===================== 542 545 … … 611 614 {% ssi /home/html/ljworld.com/includes/right_generic.html parsed %} 612 615 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 613 621 ``templatetag`` 614 622 Output one of the bits used to compose template tags. django/branches/i18n/tests/testapp/models/custom_pk.py
r682 r993 54 54 >>> employees.get_list(last_name__exact='Jones') 55 55 [Dan Jones, Fran Jones] 56 >>> employees.get_in_bulk(['ABC123', 'XYZ456']) 57 {'XYZ456': Fran Jones, 'ABC123': Dan Jones} 56 58 57 59 >>> b = businesses.Business(name='Sears') … … 63 65 >>> fran.get_business_list() 64 66 [Sears] 67 >>> businesses.get_in_bulk(['Sears']) 68 {'Sears': Sears} 65 69 """
