Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #11166 -- {% widthratio %} should return 0 when the maximum is …

…0, no matter the value.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17224 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit a4e516b593a5d4bd81a160b3b1a8cb4b23821b7d 1 parent 8767439
Aymeric Augustin authored December 17, 2011
10  django/template/defaulttags.py
@@ -435,7 +435,7 @@ def __init__(self, val_expr, max_expr, max_width):
435 435
     def render(self, context):
436 436
         try:
437 437
             value = self.val_expr.resolve(context)
438  
-            maxvalue = self.max_expr.resolve(context)
  438
+            max_value = self.max_expr.resolve(context)
439 439
             max_width = int(self.max_width.resolve(context))
440 440
         except VariableDoesNotExist:
441 441
             return ''
@@ -443,9 +443,11 @@ def render(self, context):
443 443
             raise TemplateSyntaxError("widthratio final argument must be an number")
444 444
         try:
445 445
             value = float(value)
446  
-            maxvalue = float(maxvalue)
447  
-            ratio = (value / maxvalue) * max_width
448  
-        except (ValueError, ZeroDivisionError):
  446
+            max_value = float(max_value)
  447
+            ratio = (value / max_value) * max_width
  448
+        except ZeroDivisionError:
  449
+            return '0'
  450
+        except ValueError:
449 451
             return ''
450 452
         return str(int(round(ratio)))
451 453
 
2  tests/regressiontests/templates/tests.py
@@ -1429,7 +1429,7 @@ def get_template_tests(self):
1429 1429
 
1430 1430
             ### WIDTHRATIO TAG ########################################################
1431 1431
             'widthratio01': ('{% widthratio a b 0 %}', {'a':50,'b':100}, '0'),
1432  
-            'widthratio02': ('{% widthratio a b 100 %}', {'a':0,'b':0}, ''),
  1432
+            'widthratio02': ('{% widthratio a b 100 %}', {'a':0,'b':0}, '0'),
1433 1433
             'widthratio03': ('{% widthratio a b 100 %}', {'a':0,'b':100}, '0'),
1434 1434
             'widthratio04': ('{% widthratio a b 100 %}', {'a':50,'b':100}, '50'),
1435 1435
             'widthratio05': ('{% widthratio a b 100 %}', {'a':100,'b':100}, '100'),

0 notes on commit a4e516b

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