summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorBrian Rosner <brosner@gmail.com>2009-04-01 23:41:36 +0000
committerBrian Rosner <brosner@gmail.com>2009-04-01 23:41:36 +0000
commit64e82fb648ebdd7c98fa5f1cffb1e21f1918cf4d (patch)
treef722dfae20d31582098be7de1b2cb1bfda537cb0 /django
parent624caace17dbb9e22f5a4c6c08937d68cbdbb066 (diff)
Fixed #10043 -- widthratio tag now accepts a variable for the max_width argument.
The max_width argument now passes through FilterExpression which by side-affect allows float values, but will be truncated. Thanks obeattie and Eric Holscher for patches. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10352 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
-rw-r--r--django/template/defaulttags.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py
index c375b5bb1e..2eee534830 100644
--- a/django/template/defaulttags.py
+++ b/django/template/defaulttags.py
@@ -402,12 +402,15 @@ class WidthRatioNode(Node):
try:
value = self.val_expr.resolve(context)
maxvalue = self.max_expr.resolve(context)
+ max_width = int(self.max_width.resolve(context))
except VariableDoesNotExist:
return ''
+ except ValueError:
+ raise TemplateSyntaxError("widthratio final argument must be an number")
try:
value = float(value)
maxvalue = float(maxvalue)
- ratio = (value / maxvalue) * int(self.max_width)
+ ratio = (value / maxvalue) * max_width
except (ValueError, ZeroDivisionError):
return ''
return str(int(round(ratio)))
@@ -1143,12 +1146,10 @@ def widthratio(parser, token):
if len(bits) != 4:
raise TemplateSyntaxError("widthratio takes three arguments")
tag, this_value_expr, max_value_expr, max_width = bits
- try:
- max_width = int(max_width)
- except ValueError:
- raise TemplateSyntaxError("widthratio final argument must be an integer")
+
return WidthRatioNode(parser.compile_filter(this_value_expr),
- parser.compile_filter(max_value_expr), max_width)
+ parser.compile_filter(max_value_expr),
+ parser.compile_filter(max_width))
widthratio = register.tag(widthratio)
#@register.tag