Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[1.2.X] Fixed #4976 -- Stopped humanize template tags to raise a Type…

…Error if passed a value of ``None``. Thanks, Simon G. and Adam Vandenberg.

Backport from trunk (r15000).

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@15004 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 0e651d3fd464dbc2e8c22c62dc9a62c2057efa6e 1 parent eb18ea7
Jannis Leidel jezdez authored
7 django/contrib/humanize/templatetags/humanize.py
View
@@ -43,7 +43,10 @@ def intword(value):
numbers over 1 million. For example, 1000000 becomes '1.0 million', 1200000
becomes '1.2 million' and '1200000000' becomes '1.2 billion'.
"""
- value = int(value)
+ try:
+ value = int(value)
+ except (TypeError, ValueError):
+ return value
if value < 1000000:
return value
if value < 1000000000:
@@ -66,7 +69,7 @@ def apnumber(value):
"""
try:
value = int(value)
- except ValueError:
+ except (TypeError, ValueError):
return value
if not 0 < value < 10:
return value
1  django/forms/formsets.py
View
@@ -254,6 +254,7 @@ def is_valid(self):
# We loop over every form.errors here rather than short circuiting on the
# first failure to make sure validation gets triggered for every form.
forms_valid = True
+ err = self.errors
for i in range(0, self.total_form_count()):
form = self.forms[i]
if self.can_delete:
19 tests/regressiontests/humanize/tests.py
View
@@ -31,24 +31,29 @@ def test_ordinal(self):
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',
+ 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',
+ None)
self.humanize_tester(test_list, result_list, 'intcomma')
def test_intword(self):
test_list = ('100', '1000000', '1200000', '1290000',
- '1000000000','2000000000','6000000000000')
+ '1000000000','2000000000','6000000000000',
+ None)
result_list = ('100', '1.0 million', '1.2 million', '1.3 million',
- '1.0 billion', '2.0 billion', '6.0 trillion')
+ '1.0 billion', '2.0 billion', '6.0 trillion',
+ None)
self.humanize_tester(test_list, result_list, 'intword')
def test_apnumber(self):
test_list = [str(x) for x in range(1, 11)]
+ test_list.append(None)
result_list = (u'one', u'two', u'three', u'four', u'five', u'six',
- u'seven', u'eight', u'nine', u'10')
+ u'seven', u'eight', u'nine', u'10', None)
self.humanize_tester(test_list, result_list, 'apnumber')
@@ -60,10 +65,10 @@ def test_naturalday(self):
someday = today - timedelta(days=10)
notdate = u"I'm not a date value"
- test_list = (today, yesterday, tomorrow, someday, notdate)
+ test_list = (today, yesterday, tomorrow, someday, notdate, None)
someday_result = defaultfilters.date(someday)
result_list = (_(u'today'), _(u'yesterday'), _(u'tomorrow'),
- someday_result, u"I'm not a date value")
+ someday_result, u"I'm not a date value", None)
self.humanize_tester(test_list, result_list, 'naturalday')
if __name__ == '__main__':
Please sign in to comment.
Something went wrong with that request. Please try again.