From 8b9cf79ff645db608f92143d733df24d883a26e9 Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Sun, 10 Jan 2010 21:37:20 +0000 Subject: [PATCH] Fixed #11783 -- ordinal template tag now catches TypeError. Thanks, realpolitik and punteney git-svn-id: http://code.djangoproject.com/svn/django/trunk@12199 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/humanize/templatetags/humanize.py | 2 +- tests/regressiontests/humanize/tests.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/django/contrib/humanize/templatetags/humanize.py b/django/contrib/humanize/templatetags/humanize.py index 05d322363b..3e19fed823 100644 --- a/django/contrib/humanize/templatetags/humanize.py +++ b/django/contrib/humanize/templatetags/humanize.py @@ -14,7 +14,7 @@ def ordinal(value): """ try: value = int(value) - except ValueError: + except (TypeError, ValueError): return value t = (_('th'), _('st'), _('nd'), _('rd'), _('th'), _('th'), _('th'), _('th'), _('th'), _('th')) if value % 100 in (11, 12, 13): # special case diff --git a/tests/regressiontests/humanize/tests.py b/tests/regressiontests/humanize/tests.py index 6f60c6d6f9..8b454719a1 100644 --- a/tests/regressiontests/humanize/tests.py +++ b/tests/regressiontests/humanize/tests.py @@ -22,10 +22,10 @@ class HumanizeTests(unittest.TestCase): def test_ordinal(self): test_list = ('1','2','3','4','11','12', '13','101','102','103','111', - 'something else') + 'something else', None) result_list = ('1st', '2nd', '3rd', '4th', '11th', '12th', '13th', '101st', '102nd', '103rd', - '111th', 'something else') + '111th', 'something else', None) self.humanize_tester(test_list, result_list, 'ordinal')