Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[1.2.X] Fixed #14053 -- Also localize long integers. Thanks, David Da…

…nier.

Backport from trunk (r13920).

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@13921 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 229c738a03b938fd81a4858ad51750c76d2d666c 1 parent 2511939
@jezdez jezdez authored
Showing with 19 additions and 9 deletions.
  1. +2 −2 django/utils/formats.py
  2. +17 −7 tests/regressiontests/i18n/tests.py
View
4 django/utils/formats.py
@@ -93,7 +93,7 @@ def localize(value):
Checks if value is a localizable type (date, number...) and returns it
formatted as a string using current locale format
"""
- if isinstance(value, (decimal.Decimal, float, int)):
+ if isinstance(value, (decimal.Decimal, float, int, long)):
return number_format(value)
elif isinstance(value, datetime.datetime):
return date_format(value, 'DATETIME_FORMAT')
@@ -109,7 +109,7 @@ def localize_input(value, default=None):
Checks if an input value is a localizable type and returns it
formatted with the appropriate formatting string of the current locale.
"""
- if isinstance(value, (decimal.Decimal, float, int)):
+ if isinstance(value, (decimal.Decimal, float, int, long)):
return number_format(value)
if isinstance(value, datetime.datetime):
value = datetime_safe.new_datetime(value)
View
24 tests/regressiontests/i18n/tests.py
@@ -122,12 +122,14 @@ def setUp(self):
self.d = datetime.date(2009, 12, 31)
self.dt = datetime.datetime(2009, 12, 31, 20, 50)
self.t = datetime.time(10, 15, 48)
+ self.l = 10000L
self.ctxt = Context({
'n': self.n,
't': self.t,
'd': self.d,
'dt': self.dt,
- 'f': self.f
+ 'f': self.f,
+ 'l': self.l,
})
def tearDown(self):
@@ -152,6 +154,7 @@ def test_locale_independent(self):
self.assertEqual(u'6B6B6B6B6A6', nformat(self.n, decimal_sep='A', decimal_pos=1, grouping=1, thousand_sep='B'))
self.assertEqual(u'-66666.6', nformat(-66666.666, decimal_sep='.', decimal_pos=1))
self.assertEqual(u'-66666.0', nformat(int('-66666'), decimal_sep='.', decimal_pos=1))
+ self.assertEqual(u'10000.0', nformat(self.l, decimal_sep='.', decimal_pos=1))
# date filter
self.assertEqual(u'31.12.2009 в 20:50', Template('{{ dt|date:"d.m.Y в H:i" }}').render(self.ctxt))
@@ -165,16 +168,17 @@ def test_l10n_disabled(self):
settings.USE_L10N = False
activate('ca')
try:
- self.assertEqual('N j, Y', get_format('DATE_FORMAT'))
+ self.assertEqual(u'N j, Y', get_format('DATE_FORMAT'))
self.assertEqual(0, get_format('FIRST_DAY_OF_WEEK'))
- self.assertEqual('.', get_format('DECIMAL_SEPARATOR'))
+ self.assertEqual(u'.', get_format('DECIMAL_SEPARATOR'))
self.assertEqual(u'10:15 a.m.', time_format(self.t))
self.assertEqual(u'des. 31, 2009', date_format(self.d))
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('66666.666', localize(self.n))
- self.assertEqual('99999.999', localize(self.f))
+ self.assertEqual(u'No localizable', localize('No localizable'))
+ self.assertEqual(u'66666.666', localize(self.n))
+ self.assertEqual(u'99999.999', localize(self.f))
+ self.assertEqual(u'10000', localize(self.l))
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))
@@ -245,16 +249,19 @@ def test_l10n_enabled(self):
settings.USE_THOUSAND_SEPARATOR = True
self.assertEqual(u'66.666,666', localize(self.n))
self.assertEqual(u'99.999,999', localize(self.f))
+ self.assertEqual(u'10.000', localize(self.l))
settings.USE_THOUSAND_SEPARATOR = False
self.assertEqual(u'66666,666', localize(self.n))
self.assertEqual(u'99999,999', localize(self.f))
+ self.assertEqual(u'10000', localize(self.l))
self.assertEqual(u'31 de desembre de 2009', localize(self.d))
self.assertEqual(u'31 de desembre de 2009 a les 20:50', localize(self.dt))
settings.USE_THOUSAND_SEPARATOR = True
self.assertEqual(u'66.666,666', Template('{{ n }}').render(self.ctxt))
self.assertEqual(u'99.999,999', Template('{{ f }}').render(self.ctxt))
+ self.assertEqual(u'10.000', Template('{{ l }}').render(self.ctxt))
form3 = I18nForm({
'decimal_field': u'66.666,666',
@@ -324,21 +331,24 @@ def test_l10n_enabled(self):
self.assertEqual(u'Dec. 31, 2009', date_format(self.d))
self.assertEqual(u'December 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(u'No localizable', localize('No localizable'))
settings.USE_THOUSAND_SEPARATOR = True
self.assertEqual(u'66,666.666', localize(self.n))
self.assertEqual(u'99,999.999', localize(self.f))
+ self.assertEqual(u'10,000', localize(self.l))
settings.USE_THOUSAND_SEPARATOR = False
self.assertEqual(u'66666.666', localize(self.n))
self.assertEqual(u'99999.999', localize(self.f))
+ self.assertEqual(u'10000', localize(self.l))
self.assertEqual(u'Dec. 31, 2009', localize(self.d))
self.assertEqual(u'Dec. 31, 2009, 8:50 p.m.', localize(self.dt))
settings.USE_THOUSAND_SEPARATOR = True
self.assertEqual(u'66,666.666', Template('{{ n }}').render(self.ctxt))
self.assertEqual(u'99,999.999', Template('{{ f }}').render(self.ctxt))
+ self.assertEqual(u'10,000', Template('{{ l }}').render(self.ctxt))
settings.USE_THOUSAND_SEPARATOR = False
self.assertEqual(u'66666.666', Template('{{ n }}').render(self.ctxt))
Please sign in to comment.
Something went wrong with that request. Please try again.