Ticket #16723: django-2011-08-29-pluralize-16723.patch

File django-2011-08-29-pluralize-16723.patch, 1.2 KB (added by AdamG, 4 years ago)
  • django/template/defaultfilters.py

    diff -r 6d91b5e87839 django/template/defaultfilters.py
    a b def pluralize(value, arg=u's'): 
    850850    singular_suffix, plural_suffix = bits[:2]
    851851
    852852    try:
    853         if int(value) != 1:
     853        if float(value) != 1.0:
    854854            return plural_suffix
    855855    except ValueError: # Invalid string that's not a number.
    856856        pass
  • tests/regressiontests/defaultfilters/tests.py

    diff -r 6d91b5e87839 tests/regressiontests/defaultfilters/tests.py
    a b class DefaultFiltersTests(unittest.TestC 
    498498        self.assertEqual(pluralize(0,u'y,ies'), u'ies')
    499499        self.assertEqual(pluralize(2,u'y,ies'), u'ies')
    500500        self.assertEqual(pluralize(0,u'y,ies,error'), u'')
     501        self.assertEqual(pluralize(0.5), u's')
     502        self.assertEqual(pluralize(1.0), u'')
     503        self.assertEqual(pluralize(1.5), u's')
    501504
    502505    def test_phone2numeric(self):
    503506        self.assertEqual(phone2numeric(u'0800 flowers'), u'0800 3569377')
Back to Top