summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHernan Lozano <hernantz@gmail.com>2013-02-23 13:19:21 -0300
committerClaude Paroz <claude@2xlibre.net>2013-02-23 21:48:22 +0100
commit7e6ad76b24a003bfb4ced8d9b3b22a46c1590e02 (patch)
tree2e01a7b3e1606b8b07f2db451ef69ec1738db024
parent10026c2ad0da99591567ba13afe4b489e050ca4a (diff)
Fixed #19282 -- Restored ability to pass Decimals to intcomma filter
-rw-r--r--django/contrib/humanize/templatetags/humanize.py3
-rw-r--r--django/contrib/humanize/tests.py9
2 files changed, 7 insertions, 5 deletions
diff --git a/django/contrib/humanize/templatetags/humanize.py b/django/contrib/humanize/templatetags/humanize.py
index 7e8f163174..21f4c452fa 100644
--- a/django/contrib/humanize/templatetags/humanize.py
+++ b/django/contrib/humanize/templatetags/humanize.py
@@ -1,6 +1,7 @@
from __future__ import unicode_literals
import re
from datetime import date, datetime
+from decimal import Decimal
from django import template
from django.conf import settings
@@ -35,7 +36,7 @@ def intcomma(value, use_l10n=True):
"""
if settings.USE_L10N and use_l10n:
try:
- if not isinstance(value, float):
+ if not isinstance(value, (float, Decimal)):
value = int(value)
except (TypeError, ValueError):
return intcomma(value, False)
diff --git a/django/contrib/humanize/tests.py b/django/contrib/humanize/tests.py
index c648f544d7..505edf3709 100644
--- a/django/contrib/humanize/tests.py
+++ b/django/contrib/humanize/tests.py
@@ -1,5 +1,6 @@
from __future__ import unicode_literals
import datetime
+from decimal import Decimal
try:
import pytz
@@ -58,20 +59,20 @@ class HumanizeTests(TestCase):
def test_intcomma(self):
test_list = (100, 1000, 10123, 10311, 1000000, 1234567.25,
- '100', '1000', '10123', '10311', '1000000', '1234567.1234567',
+ '100', '1000', '10123', '10311', '1000000', '1234567.1234567', Decimal('1234567.1234567'),
None)
result_list = ('100', '1,000', '10,123', '10,311', '1,000,000', '1,234,567.25',
- '100', '1,000', '10,123', '10,311', '1,000,000', '1,234,567.1234567',
+ '100', '1,000', '10,123', '10,311', '1,000,000', '1,234,567.1234567', '1,234,567.1234567',
None)
self.humanize_tester(test_list, result_list, 'intcomma')
def test_l10n_intcomma(self):
test_list = (100, 1000, 10123, 10311, 1000000, 1234567.25,
- '100', '1000', '10123', '10311', '1000000', '1234567.1234567',
+ '100', '1000', '10123', '10311', '1000000', '1234567.1234567', Decimal('1234567.1234567'),
None)
result_list = ('100', '1,000', '10,123', '10,311', '1,000,000', '1,234,567.25',
- '100', '1,000', '10,123', '10,311', '1,000,000', '1,234,567.1234567',
+ '100', '1,000', '10,123', '10,311', '1,000,000', '1,234,567.1234567', '1,234,567.1234567',
None)
with self.settings(USE_L10N=True, USE_THOUSAND_SEPARATOR=False):