Author: aaugustin
Date: 2011-12-17 02:27:14 -0800 (Sat, 17 Dec 2011)
New Revision: 17224

Modified:
   django/trunk/django/template/defaulttags.py
   django/trunk/tests/regressiontests/templates/tests.py
Log:
Fixed #11166 -- {% widthratio %} should return 0 when the maximum is 0, no 
matter the value.


Modified: django/trunk/django/template/defaulttags.py
===================================================================
--- django/trunk/django/template/defaulttags.py 2011-12-17 03:53:25 UTC (rev 
17223)
+++ django/trunk/django/template/defaulttags.py 2011-12-17 10:27:14 UTC (rev 
17224)
@@ -435,7 +435,7 @@
     def render(self, context):
         try:
             value = self.val_expr.resolve(context)
-            maxvalue = self.max_expr.resolve(context)
+            max_value = self.max_expr.resolve(context)
             max_width = int(self.max_width.resolve(context))
         except VariableDoesNotExist:
             return ''
@@ -443,9 +443,11 @@
             raise TemplateSyntaxError("widthratio final argument must be an 
number")
         try:
             value = float(value)
-            maxvalue = float(maxvalue)
-            ratio = (value / maxvalue) * max_width
-        except (ValueError, ZeroDivisionError):
+            max_value = float(max_value)
+            ratio = (value / max_value) * max_width
+        except ZeroDivisionError:
+            return '0'
+        except ValueError:
             return ''
         return str(int(round(ratio)))
 

Modified: django/trunk/tests/regressiontests/templates/tests.py
===================================================================
--- django/trunk/tests/regressiontests/templates/tests.py       2011-12-17 
03:53:25 UTC (rev 17223)
+++ django/trunk/tests/regressiontests/templates/tests.py       2011-12-17 
10:27:14 UTC (rev 17224)
@@ -1429,7 +1429,7 @@
 
             ### WIDTHRATIO TAG 
########################################################
             'widthratio01': ('{% widthratio a b 0 %}', {'a':50,'b':100}, '0'),
-            'widthratio02': ('{% widthratio a b 100 %}', {'a':0,'b':0}, ''),
+            'widthratio02': ('{% widthratio a b 100 %}', {'a':0,'b':0}, '0'),
             'widthratio03': ('{% widthratio a b 100 %}', {'a':0,'b':100}, '0'),
             'widthratio04': ('{% widthratio a b 100 %}', {'a':50,'b':100}, 
'50'),
             'widthratio05': ('{% widthratio a b 100 %}', {'a':100,'b':100}, 
'100'),

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

Reply via email to