Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #14053 -- Also localize long integers. Thanks, David Danier.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@13920 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit d80d2e8103a5d8a96863cebf433d61afa45e319e 1 parent 45d348f
Jannis Leidel authored September 27, 2010
4  django/utils/formats.py
@@ -99,7 +99,7 @@ def localize(value):
99 99
     Checks if value is a localizable type (date, number...) and returns it
100 100
     formatted as a string using current locale format
101 101
     """
102  
-    if isinstance(value, (decimal.Decimal, float, int)):
  102
+    if isinstance(value, (decimal.Decimal, float, int, long)):
103 103
         return number_format(value)
104 104
     elif isinstance(value, datetime.datetime):
105 105
         return date_format(value, 'DATETIME_FORMAT')
@@ -115,7 +115,7 @@ def localize_input(value, default=None):
115 115
     Checks if an input value is a localizable type and returns it
116 116
     formatted with the appropriate formatting string of the current locale.
117 117
     """
118  
-    if isinstance(value, (decimal.Decimal, float, int)):
  118
+    if isinstance(value, (decimal.Decimal, float, int, long)):
119 119
         return number_format(value)
120 120
     elif isinstance(value, datetime.datetime):
121 121
         value = datetime_safe.new_datetime(value)
24  tests/regressiontests/i18n/tests.py
@@ -122,12 +122,14 @@ def setUp(self):
122 122
         self.d = datetime.date(2009, 12, 31)
123 123
         self.dt = datetime.datetime(2009, 12, 31, 20, 50)
124 124
         self.t = datetime.time(10, 15, 48)
  125
+        self.l = 10000L
125 126
         self.ctxt = Context({
126 127
             'n': self.n,
127 128
             't': self.t,
128 129
             'd': self.d,
129 130
             'dt': self.dt,
130  
-            'f': self.f
  131
+            'f': self.f,
  132
+            'l': self.l,
131 133
         })
132 134
 
133 135
     def tearDown(self):
@@ -152,6 +154,7 @@ def test_locale_independent(self):
152 154
         self.assertEqual(u'6B6B6B6B6A6', nformat(self.n, decimal_sep='A', decimal_pos=1, grouping=1, thousand_sep='B'))
153 155
         self.assertEqual(u'-66666.6', nformat(-66666.666, decimal_sep='.', decimal_pos=1))
154 156
         self.assertEqual(u'-66666.0', nformat(int('-66666'), decimal_sep='.', decimal_pos=1))
  157
+        self.assertEqual(u'10000.0', nformat(self.l, decimal_sep='.', decimal_pos=1))
155 158
 
156 159
         # date filter
157 160
         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):
165 168
         settings.USE_L10N = False
166 169
         activate('ca')
167 170
         try:
168  
-            self.assertEqual('N j, Y', get_format('DATE_FORMAT'))
  171
+            self.assertEqual(u'N j, Y', get_format('DATE_FORMAT'))
169 172
             self.assertEqual(0, get_format('FIRST_DAY_OF_WEEK'))
170  
-            self.assertEqual('.', get_format('DECIMAL_SEPARATOR'))
  173
+            self.assertEqual(u'.', get_format('DECIMAL_SEPARATOR'))
171 174
             self.assertEqual(u'10:15 a.m.', time_format(self.t))
172 175
             self.assertEqual(u'des. 31, 2009', date_format(self.d))
173 176
             self.assertEqual(u'desembre 2009', date_format(self.d, 'YEAR_MONTH_FORMAT'))
174 177
             self.assertEqual(u'12/31/2009 8:50 p.m.', date_format(self.dt, 'SHORT_DATETIME_FORMAT'))
175  
-            self.assertEqual('No localizable', localize('No localizable'))
176  
-            self.assertEqual('66666.666', localize(self.n))
177  
-            self.assertEqual('99999.999', localize(self.f))
  178
+            self.assertEqual(u'No localizable', localize('No localizable'))
  179
+            self.assertEqual(u'66666.666', localize(self.n))
  180
+            self.assertEqual(u'99999.999', localize(self.f))
  181
+            self.assertEqual(u'10000', localize(self.l))
178 182
             self.assertEqual(u'des. 31, 2009', localize(self.d))
179 183
             self.assertEqual(u'des. 31, 2009, 8:50 p.m.', localize(self.dt))
180 184
             self.assertEqual(u'66666.666', Template('{{ n }}').render(self.ctxt))
@@ -245,16 +249,19 @@ def test_l10n_enabled(self):
245 249
             settings.USE_THOUSAND_SEPARATOR = True
246 250
             self.assertEqual(u'66.666,666', localize(self.n))
247 251
             self.assertEqual(u'99.999,999', localize(self.f))
  252
+            self.assertEqual(u'10.000', localize(self.l))
248 253
 
249 254
             settings.USE_THOUSAND_SEPARATOR = False
250 255
             self.assertEqual(u'66666,666', localize(self.n))
251 256
             self.assertEqual(u'99999,999', localize(self.f))
  257
+            self.assertEqual(u'10000', localize(self.l))
252 258
             self.assertEqual(u'31 de desembre de 2009', localize(self.d))
253 259
             self.assertEqual(u'31 de desembre de 2009 a les 20:50', localize(self.dt))
254 260
 
255 261
             settings.USE_THOUSAND_SEPARATOR = True
256 262
             self.assertEqual(u'66.666,666', Template('{{ n }}').render(self.ctxt))
257 263
             self.assertEqual(u'99.999,999', Template('{{ f }}').render(self.ctxt))
  264
+            self.assertEqual(u'10.000', Template('{{ l }}').render(self.ctxt))
258 265
 
259 266
             form3 = I18nForm({
260 267
                 'decimal_field': u'66.666,666',
@@ -324,21 +331,24 @@ def test_l10n_enabled(self):
324 331
             self.assertEqual(u'Dec. 31, 2009', date_format(self.d))
325 332
             self.assertEqual(u'December 2009', date_format(self.d, 'YEAR_MONTH_FORMAT'))
326 333
             self.assertEqual(u'12/31/2009 8:50 p.m.', date_format(self.dt, 'SHORT_DATETIME_FORMAT'))
327  
-            self.assertEqual('No localizable', localize('No localizable'))
  334
+            self.assertEqual(u'No localizable', localize('No localizable'))
328 335
 
329 336
             settings.USE_THOUSAND_SEPARATOR = True
330 337
             self.assertEqual(u'66,666.666', localize(self.n))
331 338
             self.assertEqual(u'99,999.999', localize(self.f))
  339
+            self.assertEqual(u'10,000', localize(self.l))
332 340
 
333 341
             settings.USE_THOUSAND_SEPARATOR = False
334 342
             self.assertEqual(u'66666.666', localize(self.n))
335 343
             self.assertEqual(u'99999.999', localize(self.f))
  344
+            self.assertEqual(u'10000', localize(self.l))
336 345
             self.assertEqual(u'Dec. 31, 2009', localize(self.d))
337 346
             self.assertEqual(u'Dec. 31, 2009, 8:50 p.m.', localize(self.dt))
338 347
 
339 348
             settings.USE_THOUSAND_SEPARATOR = True
340 349
             self.assertEqual(u'66,666.666', Template('{{ n }}').render(self.ctxt))
341 350
             self.assertEqual(u'99,999.999', Template('{{ f }}').render(self.ctxt))
  351
+            self.assertEqual(u'10,000', Template('{{ l }}').render(self.ctxt))
342 352
 
343 353
             settings.USE_THOUSAND_SEPARATOR = False
344 354
             self.assertEqual(u'66666.666', Template('{{ n }}').render(self.ctxt))

0 notes on commit d80d2e8

Please sign in to comment.
Something went wrong with that request. Please try again.