Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #4976 -- Stopped humanize template tags to raise a TypeError if…

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

git-svn-id: http://code.djangoproject.com/svn/django/trunk@15000 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 3cf8502d35cdfbb4f868a848b1f38dcc275f6be1 1 parent 75f1698
Jannis Leidel authored December 21, 2010
7  django/contrib/humanize/templatetags/humanize.py
@@ -43,7 +43,10 @@ def intword(value):
43 43
     numbers over 1 million. For example, 1000000 becomes '1.0 million', 1200000
44 44
     becomes '1.2 million' and '1200000000' becomes '1.2 billion'.
45 45
     """
46  
-    value = int(value)
  46
+    try:
  47
+        value = int(value)
  48
+    except (TypeError, ValueError):
  49
+        return value
47 50
     if value < 1000000:
48 51
         return value
49 52
     if value < 1000000000:
@@ -66,7 +69,7 @@ def apnumber(value):
66 69
     """
67 70
     try:
68 71
         value = int(value)
69  
-    except ValueError:
  72
+    except (TypeError, ValueError):
70 73
         return value
71 74
     if not 0 < value < 10:
72 75
         return value
1  django/forms/formsets.py
@@ -263,6 +263,7 @@ def is_valid(self):
263 263
         # We loop over every form.errors here rather than short circuiting on the
264 264
         # first failure to make sure validation gets triggered for every form.
265 265
         forms_valid = True
  266
+        err = self.errors
266 267
         for i in range(0, self.total_form_count()):
267 268
             form = self.forms[i]
268 269
             if self.can_delete:
19  tests/regressiontests/humanize/tests.py
@@ -32,24 +32,29 @@ def test_ordinal(self):
32 32
 
33 33
     def test_intcomma(self):
34 34
         test_list = (100, 1000, 10123, 10311, 1000000, 1234567.25,
35  
-                     '100', '1000', '10123', '10311', '1000000', '1234567.1234567')
  35
+                     '100', '1000', '10123', '10311', '1000000', '1234567.1234567',
  36
+                     None)
36 37
         result_list = ('100', '1,000', '10,123', '10,311', '1,000,000', '1,234,567.25',
37  
-                       '100', '1,000', '10,123', '10,311', '1,000,000', '1,234,567.1234567')
  38
+                       '100', '1,000', '10,123', '10,311', '1,000,000', '1,234,567.1234567',
  39
+                     None)
38 40
 
39 41
         self.humanize_tester(test_list, result_list, 'intcomma')
40 42
 
41 43
     def test_intword(self):
42 44
         test_list = ('100', '1000000', '1200000', '1290000',
43  
-                     '1000000000','2000000000','6000000000000')
  45
+                     '1000000000','2000000000','6000000000000',
  46
+                     None)
44 47
         result_list = ('100', '1.0 million', '1.2 million', '1.3 million',
45  
-                       '1.0 billion', '2.0 billion', '6.0 trillion')
  48
+                       '1.0 billion', '2.0 billion', '6.0 trillion',
  49
+                       None)
46 50
 
47 51
         self.humanize_tester(test_list, result_list, 'intword')
48 52
 
49 53
     def test_apnumber(self):
50 54
         test_list = [str(x) for x in range(1, 11)]
  55
+        test_list.append(None)
51 56
         result_list = (u'one', u'two', u'three', u'four', u'five', u'six',
52  
-                       u'seven', u'eight', u'nine', u'10')
  57
+                       u'seven', u'eight', u'nine', u'10', None)
53 58
 
54 59
         self.humanize_tester(test_list, result_list, 'apnumber')
55 60
 
@@ -61,10 +66,10 @@ def test_naturalday(self):
61 66
         someday = today - timedelta(days=10)
62 67
         notdate = u"I'm not a date value"
63 68
 
64  
-        test_list = (today, yesterday, tomorrow, someday, notdate)
  69
+        test_list = (today, yesterday, tomorrow, someday, notdate, None)
65 70
         someday_result = defaultfilters.date(someday)
66 71
         result_list = (_(u'today'), _(u'yesterday'), _(u'tomorrow'),
67  
-                       someday_result, u"I'm not a date value")
  72
+                       someday_result, u"I'm not a date value", None)
68 73
         self.humanize_tester(test_list, result_list, 'naturalday')
69 74
 
70 75
 if __name__ == '__main__':

0 notes on commit 3cf8502

Please sign in to comment.
Something went wrong with that request. Please try again.