Ticket #21959: defaulttags.diff

File defaulttags.diff, 1.5 KB (added by rmoe, 10 years ago)
  • django/template/defaulttags.py

    diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py
    index 6daf234..da29c7e 100644
    a b class WidthRatioNode(Node):  
    498498            value = float(value)
    499499            max_value = float(max_value)
    500500            ratio = (value / max_value) * max_width
     501            result = str(int(round(ratio)))
    501502        except ZeroDivisionError:
    502503            return '0'
    503         except (ValueError, TypeError):
     504        except (ValueError, TypeError, OverflowError):
    504505            return ''
    505         result = str(int(round(ratio)))
    506506
    507507        if self.asvar:
    508508            context[self.asvar] = result
  • tests/template_tests/tests.py

    diff --git a/tests/template_tests/tests.py b/tests/template_tests/tests.py
    index 4dcf028..65022b4 100644
    a b class TemplateTests(TestCase):  
    16661666
    16671667            'widthratio18': ('{% widthratio a b 100 as %}', {}, template.TemplateSyntaxError),
    16681668            'widthratio19': ('{% widthratio a b 100 not_as variable %}', {}, template.TemplateSyntaxError),
     1669            'widthratio20': ('{% widthratio a b 100 %}', {'a': float('inf'), 'b': float('inf')}, ''),
     1670            'widthratio21': ('{% widthratio a b 100 %}', {'a': float('inf'), 'b': 2}, ''),
    16691671
    16701672            ### WITH TAG ########################################################
    16711673            'with01': ('{% with key=dict.key %}{{ key }}{% endwith %}', {'dict': {'key': 50}}, '50'),
Back to Top