Code

Ticket #6296: 6296.diff

File 6296.diff, 3.1 KB (added by thejaswi_puthraya, 6 years ago)

patch and tests

Line 
1Index: django/template/defaulttags.py
2===================================================================
3--- django/template/defaulttags.py      (revision 6996)
4+++ django/template/defaulttags.py      (working copy)
5@@ -8,7 +8,7 @@
6 except NameError:
7     from django.utils.itercompat import reversed     # Python 2.3 fallback
8 
9-from django.template import Node, NodeList, Template, Context, Variable
10+from django.template import Node, NodeList, Template, Context, Variable, FilterExpression
11 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
12 from django.template import get_library, Library, InvalidTemplateLibrary
13 from django.conf import settings
14@@ -188,8 +188,8 @@
15             return ''
16 
17 class IfEqualNode(Node):
18-    def __init__(self, var1, var2, nodelist_true, nodelist_false, negate):
19-        self.var1, self.var2 = Variable(var1), Variable(var2)
20+    def __init__(self, var1, var2, nodelist_true, nodelist_false, negate, parser):
21+        self.var1, self.var2 = FilterExpression(var1, parser), FilterExpression(var2, parser)
22         self.nodelist_true, self.nodelist_false = nodelist_true, nodelist_false
23         self.negate = negate
24 
25@@ -647,7 +647,7 @@
26         parser.delete_first_token()
27     else:
28         nodelist_false = NodeList()
29-    return IfEqualNode(bits[1], bits[2], nodelist_true, nodelist_false, negate)
30+    return IfEqualNode(bits[1], bits[2], nodelist_true, nodelist_false, negate, parser)
31 
32 #@register.tag
33 def ifequal(parser, token):
34Index: tests/regressiontests/templates/tests.py
35===================================================================
36--- tests/regressiontests/templates/tests.py    (revision 6996)
37+++ tests/regressiontests/templates/tests.py    (working copy)
38@@ -570,6 +570,10 @@
39             'ifequal08': ('{% ifequal a "test" %}yes{% else %}no{% endifequal %}', {"a": "no"}, "no"),
40             'ifequal09': ('{% ifequal a "test" %}yes{% else %}no{% endifequal %}', {}, "no"),
41             'ifequal10': ('{% ifequal a b %}yes{% else %}no{% endifequal %}', {}, "yes"),
42+            'ifequal11': ('{% ifequal a|first b %}yes{% else %}no{% endifequal %}',{"a": [1, 2], "b": 1}, "yes"),
43+            'ifequal12': ('{% ifequal a|first b %}yes{% else %}no{% endifequal %}',{"a": [2, 1], "b": 1}, "no"),
44+            'ifequal13': ('{% ifequal a|first b %}yes{% else %}no{% endifequal %}',{"a": ["django", "python"], "b": "django"}, "yes"),
45+            'ifequal14': ('{% ifequal a|last "python" %}yes{% else %}no{% endifequal %}',{"a": ["django", "python"]}, "yes"),
46 
47             # SMART SPLITTING
48             'ifequal-split01': ('{% ifequal a "test man" %}yes{% else %}no{% endifequal %}', {}, "no"),
49Index: AUTHORS
50===================================================================
51--- AUTHORS     (revision 6996)
52+++ AUTHORS     (working copy)
53@@ -351,6 +351,7 @@
54     ymasuda@ethercube.com
55     Jarek Zgoda <jarek.zgoda@gmail.com>
56     Cheng Zhang
57+    Thejaswi Puthraya <thejaswi.puthraya@gmail.com>
58 
59 A big THANK YOU goes to:
60