Ticket #5756: 5756.patch
File 5756.patch, 1.9 KB (added by , 17 years ago) |
---|
-
django/template/defaulttags.py
188 188 return '' 189 189 190 190 class IfEqualNode(Node): 191 def __init__(self, va r1, var2, nodelist_true, nodelist_false, negate):192 self.va r1, self.var2 = Variable(var1), Variable(var2)191 def __init__(self, val1, val2, nodelist_true, nodelist_false, negate): 192 self.val1, self.val2 = val1, val2 193 193 self.nodelist_true, self.nodelist_false = nodelist_true, nodelist_false 194 194 self.negate = negate 195 195 … … 197 197 return "<IfEqualNode>" 198 198 199 199 def render(self, context): 200 try: 201 val1 = self.var1.resolve(context) 202 except VariableDoesNotExist: 203 val1 = None 204 try: 205 val2 = self.var2.resolve(context) 206 except VariableDoesNotExist: 207 val2 = None 200 val1, val2 = (self.val1.resolve(context, True), self.val2.resolve(context, True)) 208 201 if (self.negate and val1 != val2) or (not self.negate and val1 == val2): 209 202 return self.nodelist_true.render(context) 210 203 return self.nodelist_false.render(context) … … 640 633 if len(bits) != 3: 641 634 raise TemplateSyntaxError, "%r takes two arguments" % bits[0] 642 635 end_tag = 'end' + bits[0] 636 val1 = parser.compile_filter(bits[1]) 637 val2 = parser.compile_filter(bits[2]) 643 638 nodelist_true = parser.parse(('else', end_tag)) 644 639 token = parser.next_token() 645 640 if token.contents == 'else': … … 647 642 parser.delete_first_token() 648 643 else: 649 644 nodelist_false = NodeList() 650 return IfEqualNode( bits[1], bits[2], nodelist_true, nodelist_false, negate)645 return IfEqualNode(val1, val2, nodelist_true, nodelist_false, negate) 651 646 652 647 #@register.tag 653 648 def ifequal(parser, token):