Skip to content

Commit

Permalink
Fixed #13702 -- Made sure to actually fall back to the l10n format st…
Browse files Browse the repository at this point in the history
…rings provided in the settings, when disabled.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@13770 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
jezdez committed Sep 12, 2010
1 parent 882cba0 commit 7bb6abe
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions django/conf/global_settings.py
Expand Up @@ -370,8 +370,8 @@
# Boolean that sets whether to add thousand separator when formatting numbers # Boolean that sets whether to add thousand separator when formatting numbers
USE_THOUSAND_SEPARATOR = False USE_THOUSAND_SEPARATOR = False


# Number of digits that will be togheter, when spliting them by THOUSAND_SEPARATOR # Number of digits that will be together, when spliting them by
# 0 means no grouping, 3 means splitting by thousands... # THOUSAND_SEPARATOR. 0 means no grouping, 3 means splitting by thousands...
NUMBER_GROUPING = 0 NUMBER_GROUPING = 0


# Thousand separator symbol # Thousand separator symbol
Expand Down
20 changes: 10 additions & 10 deletions django/utils/formats.py
Expand Up @@ -79,16 +79,16 @@ def localize(value):
Checks if value is a localizable type (date, number...) and returns it Checks if value is a localizable type (date, number...) and returns it
formatted as a string using current locale format formatted as a string using current locale format
""" """
if settings.USE_L10N: if isinstance(value, (decimal.Decimal, float, int)):
if isinstance(value, (decimal.Decimal, float, int)): return number_format(value)
return number_format(value) elif isinstance(value, datetime.datetime):
elif isinstance(value, datetime.datetime): return date_format(value, 'DATETIME_FORMAT')
return date_format(value, 'DATETIME_FORMAT') elif isinstance(value, datetime.date):
elif isinstance(value, datetime.date): return date_format(value)
return date_format(value) elif isinstance(value, datetime.time):
elif isinstance(value, datetime.time): return time_format(value, 'TIME_FORMAT')
return time_format(value, 'TIME_FORMAT') else:
return value return value


def localize_input(value, default=None): def localize_input(value, default=None):
""" """
Expand Down
12 changes: 6 additions & 6 deletions tests/regressiontests/i18n/tests.py
Expand Up @@ -170,14 +170,14 @@ def test_l10n_disabled(self):
self.assertEqual(u'desembre 2009', date_format(self.d, 'YEAR_MONTH_FORMAT')) 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(u'12/31/2009 8:50 p.m.', date_format(self.dt, 'SHORT_DATETIME_FORMAT'))
self.assertEqual('No localizable', localize('No localizable')) self.assertEqual('No localizable', localize('No localizable'))
self.assertEqual(decimal.Decimal('66666.666'), localize(self.n)) self.assertEqual('66666.666', localize(self.n))
self.assertEqual(99999.999, localize(self.f)) self.assertEqual('99999.999', localize(self.f))
self.assertEqual(datetime.date(2009, 12, 31), localize(self.d)) self.assertEqual(u'des. 31, 2009', localize(self.d))
self.assertEqual(datetime.datetime(2009, 12, 31, 20, 50), localize(self.dt)) 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'66666.666', Template('{{ n }}').render(self.ctxt))
self.assertEqual(u'99999.999', Template('{{ f }}').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'des. 31, 2009', 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, 8:50 p.m.', Template('{{ dt }}').render(self.ctxt))
self.assertEqual(u'66666.67', Template('{{ n|floatformat:2 }}').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'100000.0', Template('{{ f|floatformat }}').render(self.ctxt))
self.assertEqual(u'10:15 a.m.', Template('{{ t|time:"TIME_FORMAT" }}').render(self.ctxt)) self.assertEqual(u'10:15 a.m.', Template('{{ t|time:"TIME_FORMAT" }}').render(self.ctxt))
Expand Down
2 changes: 1 addition & 1 deletion tests/regressiontests/templates/filters.py
Expand Up @@ -346,5 +346,5 @@ def get_filter_tests():
'add04': (r'{{ i|add:"16" }}', {'i': 'not_an_int'}, 'not_an_int16'), '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]'), '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)'), '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'),
} }

0 comments on commit 7bb6abe

Please sign in to comment.