Ticket #10043: widthratio-variable.diff
File widthratio-variable.diff, 2.0 KB (added by , 16 years ago) |
---|
-
template/defaulttags.py
8 8 except NameError: 9 9 from django.utils.itercompat import reversed # Python 2.3 fallback 10 10 11 from django.template import Node, NodeList, Template, Context, Variable 11 from django.template import Node, NodeList, Template, Context, Variable, FilterExpression 12 12 from django.template import TemplateSyntaxError, VariableDoesNotExist, BLOCK_TAG_START, BLOCK_TAG_END, VARIABLE_TAG_START, VARIABLE_TAG_END, SINGLE_BRACE_START, SINGLE_BRACE_END, COMMENT_TAG_START, COMMENT_TAG_END 13 13 from django.template import get_library, Library, InvalidTemplateLibrary 14 14 from django.conf import settings … … 396 396 try: 397 397 value = self.val_expr.resolve(context) 398 398 maxvalue = self.max_expr.resolve(context) 399 if isinstance(self.max_width, FilterExpression): 400 self.max_width = self.max_width.resolve(context) 401 self.max_width = int(self.max_width) 399 402 except VariableDoesNotExist: 400 403 return '' 404 except ValueError: 405 raise TemplateSyntaxError("widthratio final argument must be an integer") 401 406 try: 402 407 value = float(value) 403 408 maxvalue = float(maxvalue) … … 1103 1108 if len(bits) != 4: 1104 1109 raise TemplateSyntaxError("widthratio takes three arguments") 1105 1110 tag, this_value_expr, max_value_expr, max_width = bits 1106 try: 1107 max_width = int(max_width) 1108 except ValueError: 1109 raise TemplateSyntaxError("widthratio final argument must be an integer") 1111 1110 1112 return WidthRatioNode(parser.compile_filter(this_value_expr), 1111 parser.compile_filter(max_value_expr), max_width) 1113 parser.compile_filter(max_value_expr), 1114 parser.compile_filter(max_width)) 1112 1115 widthratio = register.tag(widthratio) 1113 1116 1114 1117 #@register.tag