Ticket #6296: 6296.diff

File 6296.diff, 3.1 KB (added by Thejaswi Puthraya, 17 years ago)

patch and tests

  • django/template/defaulttags.py

     
    88except NameError:
    99    from django.utils.itercompat import reversed     # Python 2.3 fallback
    1010
    11 from django.template import Node, NodeList, Template, Context, Variable
     11from django.template import Node, NodeList, Template, Context, Variable, FilterExpression
    1212from 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
    1313from django.template import get_library, Library, InvalidTemplateLibrary
    1414from django.conf import settings
     
    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, var1, var2, nodelist_true, nodelist_false, negate, parser):
     192        self.var1, self.var2 = FilterExpression(var1, parser), FilterExpression(var2, parser)
    193193        self.nodelist_true, self.nodelist_false = nodelist_true, nodelist_false
    194194        self.negate = negate
    195195
     
    647647        parser.delete_first_token()
    648648    else:
    649649        nodelist_false = NodeList()
    650     return IfEqualNode(bits[1], bits[2], nodelist_true, nodelist_false, negate)
     650    return IfEqualNode(bits[1], bits[2], nodelist_true, nodelist_false, negate, parser)
    651651
    652652#@register.tag
    653653def ifequal(parser, token):
  • tests/regressiontests/templates/tests.py

     
    570570            'ifequal08': ('{% ifequal a "test" %}yes{% else %}no{% endifequal %}', {"a": "no"}, "no"),
    571571            'ifequal09': ('{% ifequal a "test" %}yes{% else %}no{% endifequal %}', {}, "no"),
    572572            'ifequal10': ('{% ifequal a b %}yes{% else %}no{% endifequal %}', {}, "yes"),
     573            'ifequal11': ('{% ifequal a|first b %}yes{% else %}no{% endifequal %}',{"a": [1, 2], "b": 1}, "yes"),
     574            'ifequal12': ('{% ifequal a|first b %}yes{% else %}no{% endifequal %}',{"a": [2, 1], "b": 1}, "no"),
     575            'ifequal13': ('{% ifequal a|first b %}yes{% else %}no{% endifequal %}',{"a": ["django", "python"], "b": "django"}, "yes"),
     576            'ifequal14': ('{% ifequal a|last "python" %}yes{% else %}no{% endifequal %}',{"a": ["django", "python"]}, "yes"),
    573577
    574578            # SMART SPLITTING
    575579            'ifequal-split01': ('{% ifequal a "test man" %}yes{% else %}no{% endifequal %}', {}, "no"),
  • AUTHORS

     
    351351    ymasuda@ethercube.com
    352352    Jarek Zgoda <jarek.zgoda@gmail.com>
    353353    Cheng Zhang
     354    Thejaswi Puthraya <thejaswi.puthraya@gmail.com>
    354355
    355356A big THANK YOU goes to:
    356357
Back to Top