Author: jacob
Date: 2009-03-31 13:17:21 -0500 (Tue, 31 Mar 2009)
New Revision: 10278

Modified:
   django/trunk/django/template/defaultfilters.py
   django/trunk/tests/regressiontests/defaultfilters/tests.py
Log:
Fixed #10513: floatformat now works with floatish things, not just real floats. 
Thanks, Alex.

Modified: django/trunk/django/template/defaultfilters.py
===================================================================
--- django/trunk/django/template/defaultfilters.py      2009-03-31 18:15:01 UTC 
(rev 10277)
+++ django/trunk/django/template/defaultfilters.py      2009-03-31 18:17:21 UTC 
(rev 10278)
@@ -149,7 +149,9 @@
     except InvalidOperation:
         if input_val in special_floats:
             return input_val
-        else:
+        try:
+            d = Decimal(force_unicode(float(text)))
+        except (ValueError, InvalidOperation, TypeError, UnicodeEncodeError):
             return u''
     try:
         p = int(arg)

Modified: django/trunk/tests/regressiontests/defaultfilters/tests.py
===================================================================
--- django/trunk/tests/regressiontests/defaultfilters/tests.py  2009-03-31 
18:15:01 UTC (rev 10277)
+++ django/trunk/tests/regressiontests/defaultfilters/tests.py  2009-03-31 
18:17:21 UTC (rev 10278)
@@ -35,8 +35,8 @@
 u''
 >>> floatformat(13.1031, u'bar')
 u'13.1031'
->>> floatformat(18.125, 2) 
-u'18.13' 
+>>> floatformat(18.125, 2)
+u'18.13'
 >>> floatformat(u'foo', u'bar')
 u''
 >>> floatformat(u'¿Cómo esta usted?')
@@ -53,6 +53,15 @@
 >>> floatformat(nan) == unicode(nan)
 True
 
+>>> class FloatWrapper(object):
+...     def __init__(self, value):
+...         self.value = value
+...     def __float__(self):
+...         return self.value
+
+>>> floatformat(FloatWrapper(11.000001), -2)
+u'11.00'
+
 >>> addslashes(u'"double quotes" and \'single quotes\'')
 u'\\"double quotes\\" and \\\'single quotes\\\''
 
@@ -180,23 +189,23 @@
 u'<a href="http://31characteruri.com/test/"; rel="nofollow">...</a>'
 
 # Check normal urlize
->>> urlize('http://google.com') 
+>>> urlize('http://google.com')
 u'<a href="http://google.com"; rel="nofollow">http://google.com</a>'
 
->>> urlize('http://google.com/') 
+>>> urlize('http://google.com/')
 u'<a href="http://google.com/"; rel="nofollow">http://google.com/</a>'
 
->>> urlize('www.google.com') 
+>>> urlize('www.google.com')
 u'<a href="http://www.google.com"; rel="nofollow">www.google.com</a>'
 
->>> urlize('djangoproject.org') 
+>>> urlize('djangoproject.org')
 u'<a href="http://djangoproject.org"; rel="nofollow">djangoproject.org</a>'
 
->>> urlize('[email protected]') 
+>>> urlize('[email protected]')
 u'<a href="mailto:[email protected]";>[email protected]</a>'
 
 # Check urlize with https addresses
->>> urlize('https://google.com') 
+>>> urlize('https://google.com')
 u'<a href="https://google.com"; rel="nofollow">https://google.com</a>'
 
 


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to