mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
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
This commit is contained in:
@@ -435,7 +435,7 @@ class WidthRatioNode(Node):
|
||||
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 @@ class WidthRatioNode(Node):
|
||||
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)))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user