mirror of
https://github.com/django/django.git
synced 2024-12-01 15:42:04 +01:00
Fixed #13702 -- Made sure to actually fall back to the l10n format strings provided in the settings, when disabled.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@13770 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
882cba0f69
commit
7bb6abed12
@ -370,8 +370,8 @@ DECIMAL_SEPARATOR = '.'
|
||||
# Boolean that sets whether to add thousand separator when formatting numbers
|
||||
USE_THOUSAND_SEPARATOR = False
|
||||
|
||||
# Number of digits that will be togheter, when spliting them by THOUSAND_SEPARATOR
|
||||
# 0 means no grouping, 3 means splitting by thousands...
|
||||
# Number of digits that will be together, when spliting them by
|
||||
# THOUSAND_SEPARATOR. 0 means no grouping, 3 means splitting by thousands...
|
||||
NUMBER_GROUPING = 0
|
||||
|
||||
# Thousand separator symbol
|
||||
|
@ -79,16 +79,16 @@ def localize(value):
|
||||
Checks if value is a localizable type (date, number...) and returns it
|
||||
formatted as a string using current locale format
|
||||
"""
|
||||
if settings.USE_L10N:
|
||||
if isinstance(value, (decimal.Decimal, float, int)):
|
||||
return number_format(value)
|
||||
elif isinstance(value, datetime.datetime):
|
||||
return date_format(value, 'DATETIME_FORMAT')
|
||||
elif isinstance(value, datetime.date):
|
||||
return date_format(value)
|
||||
elif isinstance(value, datetime.time):
|
||||
return time_format(value, 'TIME_FORMAT')
|
||||
return value
|
||||
if isinstance(value, (decimal.Decimal, float, int)):
|
||||
return number_format(value)
|
||||
elif isinstance(value, datetime.datetime):
|
||||
return date_format(value, 'DATETIME_FORMAT')
|
||||
elif isinstance(value, datetime.date):
|
||||
return date_format(value)
|
||||
elif isinstance(value, datetime.time):
|
||||
return time_format(value, 'TIME_FORMAT')
|
||||
else:
|
||||
return value
|
||||
|
||||
def localize_input(value, default=None):
|
||||
"""
|
||||
|
@ -170,14 +170,14 @@ class FormattingTests(TestCase):
|
||||
self.assertEqual(u'desembre 2009', date_format(self.d, 'YEAR_MONTH_FORMAT'))
|
||||
self.assertEqual(u'12/31/2009 8:50 p.m.', date_format(self.dt, 'SHORT_DATETIME_FORMAT'))
|
||||
self.assertEqual('No localizable', localize('No localizable'))
|
||||
self.assertEqual(decimal.Decimal('66666.666'), localize(self.n))
|
||||
self.assertEqual(99999.999, localize(self.f))
|
||||
self.assertEqual(datetime.date(2009, 12, 31), localize(self.d))
|
||||
self.assertEqual(datetime.datetime(2009, 12, 31, 20, 50), localize(self.dt))
|
||||
self.assertEqual('66666.666', localize(self.n))
|
||||
self.assertEqual('99999.999', localize(self.f))
|
||||
self.assertEqual(u'des. 31, 2009', localize(self.d))
|
||||
self.assertEqual(u'des. 31, 2009, 8:50 p.m.', localize(self.dt))
|
||||
self.assertEqual(u'66666.666', Template('{{ n }}').render(self.ctxt))
|
||||
self.assertEqual(u'99999.999', Template('{{ f }}').render(self.ctxt))
|
||||
self.assertEqual(u'2009-12-31', Template('{{ d }}').render(self.ctxt))
|
||||
self.assertEqual(u'2009-12-31 20:50:00', Template('{{ dt }}').render(self.ctxt))
|
||||
self.assertEqual(u'des. 31, 2009', Template('{{ d }}').render(self.ctxt))
|
||||
self.assertEqual(u'des. 31, 2009, 8:50 p.m.', Template('{{ dt }}').render(self.ctxt))
|
||||
self.assertEqual(u'66666.67', Template('{{ n|floatformat:2 }}').render(self.ctxt))
|
||||
self.assertEqual(u'100000.0', Template('{{ f|floatformat }}').render(self.ctxt))
|
||||
self.assertEqual(u'10:15 a.m.', Template('{{ t|time:"TIME_FORMAT" }}').render(self.ctxt))
|
||||
|
@ -346,5 +346,5 @@ def get_filter_tests():
|
||||
'add04': (r'{{ i|add:"16" }}', {'i': 'not_an_int'}, 'not_an_int16'),
|
||||
'add05': (r'{{ l1|add:l2 }}', {'l1': [1, 2], 'l2': [3, 4]}, '[1, 2, 3, 4]'),
|
||||
'add06': (r'{{ t1|add:t2 }}', {'t1': (3, 4), 't2': (1, 2)}, '(3, 4, 1, 2)'),
|
||||
'add07': (r'{{ d|add:t }}', {'d': date(2000, 1, 1), 't': timedelta(10)}, '2000-01-11'),
|
||||
'add07': (r'{{ d|add:t }}', {'d': date(2000, 1, 1), 't': timedelta(10)}, 'Jan. 11, 2000'),
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user