Author: garcia_marc
Date: 2009-07-09 04:22:14 -0500 (Thu, 09 Jul 2009)
New Revision: 11207
Modified:
django/branches/soc2009/i18n-improvements/django/contrib/admin/media/js/calendar.js
django/branches/soc2009/i18n-improvements/django/utils/formats.py
django/branches/soc2009/i18n-improvements/django/views/i18n.py
Log:
[soc2009/i18n] formats made available for javascript, and used to change the
first day of week in admin calendar
Modified:
django/branches/soc2009/i18n-improvements/django/contrib/admin/media/js/calendar.js
===================================================================
---
django/branches/soc2009/i18n-improvements/django/contrib/admin/media/js/calendar.js
2009-07-09 02:37:20 UTC (rev 11206)
+++
django/branches/soc2009/i18n-improvements/django/contrib/admin/media/js/calendar.js
2009-07-09 09:22:14 UTC (rev 11207)
@@ -25,6 +25,7 @@
var CalendarNamespace = {
monthsOfYear: gettext('January February March April May June July August
September October November December').split(' '),
daysOfWeek: gettext('S M T W T F S').split(' '),
+ firstDayOfWeek: parseInt(gettext('FIRST_DAY_OF_WEEK')),
isLeapYear: function(year) {
return (((year % 4)==0) && ((year % 100)!=0) || ((year % 400)==0));
},
@@ -56,10 +57,10 @@
// Draw days-of-week header
var tableRow = quickElement('tr', tableBody);
for (var i = 0; i < 7; i++) {
- quickElement('th', tableRow, CalendarNamespace.daysOfWeek[i]);
+ quickElement('th', tableRow, CalendarNamespace.daysOfWeek[(i +
CalendarNamespace.firstDayOfWeek) % 7]);
}
- var startingPos = new Date(year, month-1, 1).getDay();
+ var startingPos = new Date(year, month-1, 1 -
CalendarNamespace.firstDayOfWeek).getDay();
var days = CalendarNamespace.getDaysInMonth(month, year);
// Draw blanks before first of month
Modified: django/branches/soc2009/i18n-improvements/django/utils/formats.py
===================================================================
--- django/branches/soc2009/i18n-improvements/django/utils/formats.py
2009-07-09 02:37:20 UTC (rev 11206)
+++ django/branches/soc2009/i18n-improvements/django/utils/formats.py
2009-07-09 09:22:14 UTC (rev 11207)
@@ -15,32 +15,36 @@
"""
return getattr(settings, format_type)
-def getformat_real(format_type):
+def formats_module():
"""
- For a specific format type, returns the format for the
- current language (locale) defaulting to the format on settings.
- format_type is the name of the format, for example 'DATE_FORMAT'
+ Returns the formats module for the current locale. It can be the
+ custom one from the user, or Django's default.
"""
- import_formats = lambda s: import_module('.formats',
'django.conf.locale.%s' % s)
- module = format = None
if settings.FORMAT_MODULE_PATH:
try:
- module = import_module('.formats', '%s.%s' %
(settings.FORMAT_MODULE_PATH, get_language()))
+ return import_module('.formats', '%s.%s' %
(settings.FORMAT_MODULE_PATH, get_language()))
except ImportError:
pass
- if not module:
- try:
- module = import_module('.formats', 'django.conf.locale.%s' %
get_language())
- except ImportError:
- pass
+ try:
+ return import_module('.formats', 'django.conf.locale.%s' %
get_language())
+ except ImportError:
+ return None
+
+def getformat_real(format_type):
+ """
+ For a specific format type, returns the format for the
+ current language (locale) defaulting to the format on settings.
+ format_type is the name of the format, for example 'DATE_FORMAT'
+ """
+ module = formats_module()
if module:
try:
- format = getattr(module, format_type)
+ return getattr(module, format_type)
except AttributeError:
pass
- return format or getformat_null(format_type)
+ return getformat_null(format_type)
# getformat will just return the value on setings if
# we don't use i18n in our project
Modified: django/branches/soc2009/i18n-improvements/django/views/i18n.py
===================================================================
--- django/branches/soc2009/i18n-improvements/django/views/i18n.py
2009-07-09 02:37:20 UTC (rev 11206)
+++ django/branches/soc2009/i18n-improvements/django/views/i18n.py
2009-07-09 09:22:14 UTC (rev 11207)
@@ -3,6 +3,7 @@
from django.utils import importlib
from django.utils.translation import check_for_language, activate, to_locale,
get_language
from django.utils.text import javascript_quote
+from django.utils.formats import formats_module
import os
import gettext as gettext_module
@@ -32,6 +33,17 @@
response.set_cookie(settings.LANGUAGE_COOKIE_NAME, lang_code)
return response
+def get_formats():
+ """
+ Returns an iterator over all formats in formats file
+ """
+ module = formats_module()
+ result = {}
+ for attr in dir(module):
+ if attr[:2] != '__':
+ result[attr] = getattr(module, attr)
+ return result
+
NullSource = """
/* gettext identity library */
@@ -185,10 +197,13 @@
else:
raise TypeError, k
csrc.sort()
- for k,v in pdict.items():
+ for k, v in pdict.items():
src.append("catalog['%s'] = [%s];\n" % (javascript_quote(k),
','.join(["''"]*(v+1))))
+ for k, v in get_formats().items():
+ src.append("catalog['%s'] = '%s';\n" % (javascript_quote(k),
javascript_quote(unicode(v))))
src.extend(csrc)
src.append(LibFoot)
src.append(InterPolate)
src = ''.join(src)
return http.HttpResponse(src, 'text/javascript')
+
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---