From 868ff4e37c1e4cfaf7283496c24f6e711ad66005 Mon Sep 17 00:00:00 2001 From: Moayad Mardini Date: Tue, 10 Jun 2014 21:28:32 +0300 Subject: [PATCH] Fixed #22798 -- `pluralize()` now adds plural_suffix for any `1 < d < 2` Thanks Odd_Bloke for the report. --- django/template/defaultfilters.py | 2 +- tests/defaultfilters/tests.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py index e6a0c619dc..c5839197df 100644 --- a/django/template/defaultfilters.py +++ b/django/template/defaultfilters.py @@ -934,7 +934,7 @@ def pluralize(value, arg='s'): singular_suffix, plural_suffix = bits[:2] try: - if int(value) != 1: + if float(value) != 1: return plural_suffix except ValueError: # Invalid string that's not a number. pass diff --git a/tests/defaultfilters/tests.py b/tests/defaultfilters/tests.py index ab6ff80961..7ebef193fa 100644 --- a/tests/defaultfilters/tests.py +++ b/tests/defaultfilters/tests.py @@ -654,6 +654,11 @@ class DefaultFiltersTests(TestCase): self.assertEqual(pluralize(1), '') self.assertEqual(pluralize(0), 's') self.assertEqual(pluralize(2), 's') + + # Ticket #22798 + self.assertEqual(pluralize(0.5), 's') + self.assertEqual(pluralize(1.5), 's') + self.assertEqual(pluralize(decimal.Decimal(1)), '') self.assertEqual(pluralize(decimal.Decimal(0)), 's') self.assertEqual(pluralize(decimal.Decimal(2)), 's')