[1.0.X] Fixed #10513: floatformat now works with floatish things, not just real floats. Thanks, Alex. Backport of [10278] from trunk.
git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@10299 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
4a3139d63e
commit
377cc9c850
|
@ -149,7 +149,9 @@ def floatformat(text, arg=-1):
|
||||||
except InvalidOperation:
|
except InvalidOperation:
|
||||||
if input_val in special_floats:
|
if input_val in special_floats:
|
||||||
return input_val
|
return input_val
|
||||||
else:
|
try:
|
||||||
|
d = Decimal(force_unicode(float(text)))
|
||||||
|
except (ValueError, InvalidOperation, TypeError, UnicodeEncodeError):
|
||||||
return u''
|
return u''
|
||||||
try:
|
try:
|
||||||
p = int(arg)
|
p = int(arg)
|
||||||
|
|
|
@ -53,6 +53,15 @@ True
|
||||||
>>> floatformat(nan) == unicode(nan)
|
>>> floatformat(nan) == unicode(nan)
|
||||||
True
|
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\'')
|
>>> addslashes(u'"double quotes" and \'single quotes\'')
|
||||||
u'\\"double quotes\\" and \\\'single quotes\\\''
|
u'\\"double quotes\\" and \\\'single quotes\\\''
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue