From 7bb6abed129015ad447bd78506698f34c4d8273b Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Sun, 12 Sep 2010 19:40:44 +0000 Subject: [PATCH] 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 --- django/conf/global_settings.py | 4 ++-- django/utils/formats.py | 20 ++++++++++---------- tests/regressiontests/i18n/tests.py | 12 ++++++------ tests/regressiontests/templates/filters.py | 2 +- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/django/conf/global_settings.py b/django/conf/global_settings.py index 6033297e5c1..2714bfb9ab4 100644 --- a/django/conf/global_settings.py +++ b/django/conf/global_settings.py @@ -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 diff --git a/django/utils/formats.py b/django/utils/formats.py index 31027abd23f..372998f2215 100644 --- a/django/utils/formats.py +++ b/django/utils/formats.py @@ -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): """ diff --git a/tests/regressiontests/i18n/tests.py b/tests/regressiontests/i18n/tests.py index 32c991a436b..8c1c7f3d8bc 100644 --- a/tests/regressiontests/i18n/tests.py +++ b/tests/regressiontests/i18n/tests.py @@ -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)) diff --git a/tests/regressiontests/templates/filters.py b/tests/regressiontests/templates/filters.py index d351c550b7d..af34c58a9f8 100644 --- a/tests/regressiontests/templates/filters.py +++ b/tests/regressiontests/templates/filters.py @@ -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'), }