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
This commit is contained in:
Adrian Holovaty 2010-01-10 21:37:20 +00:00
parent a4b0947a92
commit 8b9cf79ff6
2 changed files with 3 additions and 3 deletions

View File

@ -14,7 +14,7 @@ def ordinal(value):
""" """
try: try:
value = int(value) value = int(value)
except ValueError: except (TypeError, ValueError):
return value return value
t = (_('th'), _('st'), _('nd'), _('rd'), _('th'), _('th'), _('th'), _('th'), _('th'), _('th')) t = (_('th'), _('st'), _('nd'), _('rd'), _('th'), _('th'), _('th'), _('th'), _('th'), _('th'))
if value % 100 in (11, 12, 13): # special case if value % 100 in (11, 12, 13): # special case

View File

@ -22,10 +22,10 @@ class HumanizeTests(unittest.TestCase):
def test_ordinal(self): def test_ordinal(self):
test_list = ('1','2','3','4','11','12', test_list = ('1','2','3','4','11','12',
'13','101','102','103','111', '13','101','102','103','111',
'something else') 'something else', None)
result_list = ('1st', '2nd', '3rd', '4th', '11th', result_list = ('1st', '2nd', '3rd', '4th', '11th',
'12th', '13th', '101st', '102nd', '103rd', '12th', '13th', '101st', '102nd', '103rd',
'111th', 'something else') '111th', 'something else', None)
self.humanize_tester(test_list, result_list, 'ordinal') self.humanize_tester(test_list, result_list, 'ordinal')