Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #19282 -- Restored ability to pass Decimals to intcomma filter

  • Loading branch information...
commit 7e6ad76b24a003bfb4ced8d9b3b22a46c1590e02 1 parent 10026c2
hernantz authored February 23, 2013 claudep committed February 23, 2013
3  django/contrib/humanize/templatetags/humanize.py
... ...
@@ -1,6 +1,7 @@
1 1
 from __future__ import unicode_literals
2 2
 import re
3 3
 from datetime import date, datetime
  4
+from decimal import Decimal
4 5
 
5 6
 from django import template
6 7
 from django.conf import settings
@@ -35,7 +36,7 @@ def intcomma(value, use_l10n=True):
35 36
     """
36 37
     if settings.USE_L10N and use_l10n:
37 38
         try:
38  
-            if not isinstance(value, float):
  39
+            if not isinstance(value, (float, Decimal)):
39 40
                 value = int(value)
40 41
         except (TypeError, ValueError):
41 42
             return intcomma(value, False)
9  django/contrib/humanize/tests.py
... ...
@@ -1,5 +1,6 @@
1 1
 from __future__ import unicode_literals
2 2
 import datetime
  3
+from decimal import Decimal
3 4
 
4 5
 try:
5 6
     import pytz
@@ -58,20 +59,20 @@ def test_ordinal(self):
58 59
 
59 60
     def test_intcomma(self):
60 61
         test_list = (100, 1000, 10123, 10311, 1000000, 1234567.25,
61  
-                     '100', '1000', '10123', '10311', '1000000', '1234567.1234567',
  62
+                     '100', '1000', '10123', '10311', '1000000', '1234567.1234567', Decimal('1234567.1234567'),
62 63
                      None)
63 64
         result_list = ('100', '1,000', '10,123', '10,311', '1,000,000', '1,234,567.25',
64  
-                       '100', '1,000', '10,123', '10,311', '1,000,000', '1,234,567.1234567',
  65
+                       '100', '1,000', '10,123', '10,311', '1,000,000', '1,234,567.1234567', '1,234,567.1234567',
65 66
                      None)
66 67
 
67 68
         self.humanize_tester(test_list, result_list, 'intcomma')
68 69
 
69 70
     def test_l10n_intcomma(self):
70 71
         test_list = (100, 1000, 10123, 10311, 1000000, 1234567.25,
71  
-                     '100', '1000', '10123', '10311', '1000000', '1234567.1234567',
  72
+                     '100', '1000', '10123', '10311', '1000000', '1234567.1234567', Decimal('1234567.1234567'),
72 73
                      None)
73 74
         result_list = ('100', '1,000', '10,123', '10,311', '1,000,000', '1,234,567.25',
74  
-                       '100', '1,000', '10,123', '10,311', '1,000,000', '1,234,567.1234567',
  75
+                       '100', '1,000', '10,123', '10,311', '1,000,000', '1,234,567.1234567', '1,234,567.1234567',
75 76
                      None)
76 77
 
77 78
         with self.settings(USE_L10N=True, USE_THOUSAND_SEPARATOR=False):

0 notes on commit 7e6ad76

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