summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
Diffstat (limited to 'django')
-rw-r--r--django/template/defaultfilters.py16
-rw-r--r--django/utils/formats.py25
-rw-r--r--django/views/i18n.py18
3 files changed, 39 insertions, 20 deletions
diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py
index 94108f2d23..d31783949a 100644
--- a/django/template/defaultfilters.py
+++ b/django/template/defaultfilters.py
@@ -18,7 +18,7 @@ from django.conf import settings
from django.utils.translation import ugettext, ungettext
from django.utils.encoding import force_unicode, iri_to_uri
from django.utils.safestring import mark_safe, SafeData
-from django.utils.formats import number_format
+from django.utils.formats import date_format, number_format
register = Library()
@@ -685,9 +685,12 @@ def date(value, arg=None):
if arg is None:
arg = settings.DATE_FORMAT
try:
- return format(value, arg)
+ return date_format(value, arg)
except AttributeError:
- return ''
+ try:
+ return format(value, arg)
+ except AttributeError:
+ return ''
date.is_safe = False
def time(value, arg=None):
@@ -698,9 +701,12 @@ def time(value, arg=None):
if arg is None:
arg = settings.TIME_FORMAT
try:
- return time_format(value, arg)
+ return date_format(value, arg)
except AttributeError:
- return ''
+ try:
+ return time_format(value, arg)
+ except AttributeError:
+ return ''
time.is_safe = False
def timesince(value, arg=None):
diff --git a/django/utils/formats.py b/django/utils/formats.py
index 8aece8a239..cf6f2a1fc2 100644
--- a/django/utils/formats.py
+++ b/django/utils/formats.py
@@ -15,35 +15,40 @@ def getformat_null(format_type):
"""
return getattr(settings, format_type)
-def formats_module():
+def project_formats_module():
"""
- Returns the formats module for the current locale. It can be the
- custom one from the user, or Django's default.
+ Returns the formats module for the current locale, defined
+ on the project
"""
if settings.FORMAT_MODULE_PATH:
try:
return import_module('.formats', '%s.%s' % (settings.FORMAT_MODULE_PATH, get_language()))
except ImportError:
pass
+ return None
+def django_formats_module():
+ """
+ Returns the formats module for the current locale, defined
+ on Django
+ """
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:
- return getattr(module, format_type)
- except AttributeError:
- pass
+ for module in (project_formats_module(), django_formats_module()):
+ if module:
+ try:
+ return getattr(module, format_type)
+ except AttributeError:
+ pass
return getformat_null(format_type)
# getformat will just return the value on setings if
diff --git a/django/views/i18n.py b/django/views/i18n.py
index eaa4723f94..e70cd3eca3 100644
--- a/django/views/i18n.py
+++ b/django/views/i18n.py
@@ -3,7 +3,7 @@ from django.conf import settings
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
+from django.utils.formats import project_formats_module, django_formats_module
import os
import gettext as gettext_module
@@ -37,11 +37,19 @@ def get_formats():
"""
Returns an iterator over all formats in formats file
"""
- module = formats_module()
+ FORMAT_SETTINGS = ('DATE_FORMAT', 'DATETIME_FORMAT', 'TIME_FORMAT',
+ 'YEAR_MONTH_FORMAT', 'MONTH_DAY_FORMAT', 'SHORT_DATE_FORMAT',
+ 'SHORT_DATETIME_FORMAT', 'FIRST_DAY_OF_WEEK', 'DECIMAL_SEPARATOR',
+ 'THOUSAND_SEPARATOR', 'NUMBER_GROUPING')
+
result = {}
- for attr in dir(module):
- if attr[:2] != '__':
- result[attr] = getattr(module, attr)
+ for module in (settings, django_formats_module(), project_formats_module()):
+ if module:
+ for attr in FORMAT_SETTINGS:
+ try:
+ result[attr] = getattr(module, attr)
+ except AttributeError:
+ pass
return result
NullSource = """