Ticket #10513: floatfilter-__float__-regression.diff

File floatfilter-__float__-regression.diff, 1.1 KB (added by steingrd, 16 years ago)

support float objects with regression test

  • django/template/defaultfilters.py

    diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py
    index cb16e4b..e1e39dd 100644
    a b def floatformat(text, arg=-1):  
    141141    representation of that value will be displayed.
    142142    """
    143143
     144    if hasattr(text, '__float__'):
     145        text = float(text)
     146
    144147    try:
    145148        input_val = force_unicode(text)
    146149        d = Decimal(input_val)
  • tests/regressiontests/defaultfilters/tests.py

    diff --git a/tests/regressiontests/defaultfilters/tests.py b/tests/regressiontests/defaultfilters/tests.py
    index a97596f..d86e030 100644
    a b True  
    5252>>> nan = pos_inf / pos_inf
    5353>>> floatformat(nan) == unicode(nan)
    5454True
     55>>> class FloatWrapper(object):
     56...    def __init__(self, value): self.value = value
     57...    def __float__(self): return self.value
     58...
     59>>> floatformat(FloatWrapper(11.000001), -2)
     60u'11.00'
     61
    5562
    5663>>> addslashes(u'"double quotes" and \'single quotes\'')
    5764u'\\"double quotes\\" and \\\'single quotes\\\''
Back to Top