Ticket #5756: 5756.patch

File 5756.patch, 1.9 KB (added by Collin Grady <cgrady@…>, 17 years ago)
  • django/template/defaulttags.py

     
    188188            return ''
    189189
    190190class IfEqualNode(Node):
    191     def __init__(self, var1, var2, nodelist_true, nodelist_false, negate):
    192         self.var1, self.var2 = Variable(var1), Variable(var2)
     191    def __init__(self, val1, val2, nodelist_true, nodelist_false, negate):
     192        self.val1, self.val2 = val1, val2
    193193        self.nodelist_true, self.nodelist_false = nodelist_true, nodelist_false
    194194        self.negate = negate
    195195
     
    197197        return "<IfEqualNode>"
    198198
    199199    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))
    208201        if (self.negate and val1 != val2) or (not self.negate and val1 == val2):
    209202            return self.nodelist_true.render(context)
    210203        return self.nodelist_false.render(context)
     
    640633    if len(bits) != 3:
    641634        raise TemplateSyntaxError, "%r takes two arguments" % bits[0]
    642635    end_tag = 'end' + bits[0]
     636    val1 = parser.compile_filter(bits[1])
     637    val2 = parser.compile_filter(bits[2])
    643638    nodelist_true = parser.parse(('else', end_tag))
    644639    token = parser.next_token()
    645640    if token.contents == 'else':
     
    647642        parser.delete_first_token()
    648643    else:
    649644        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)
    651646
    652647#@register.tag
    653648def ifequal(parser, token):
Back to Top