summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorAlasdair Nicol <alasdair@thenicols.net>2016-04-09 16:25:00 +0100
committerTim Graham <timograham@gmail.com>2016-04-09 13:01:15 -0400
commitc16b9dd8e0ae757616e9accbaffecc521191ee98 (patch)
tree691989f2102021cbbbad9fb27b3a28e10fc602e3 /django
parentc10db4bd1b069739687b99d6b32b946634237431 (diff)
Fixed #26479 -- Added 'is not' operator to the if tag.
Diffstat (limited to 'django')
-rw-r--r--django/template/smartif.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/django/template/smartif.py b/django/template/smartif.py
index 718c457c60..b5ae510b0f 100644
--- a/django/template/smartif.py
+++ b/django/template/smartif.py
@@ -97,6 +97,7 @@ OPERATORS = {
'in': infix(9, lambda context, x, y: x.eval(context) in y.eval(context)),
'not in': infix(9, lambda context, x, y: x.eval(context) not in y.eval(context)),
'is': infix(10, lambda context, x, y: x.eval(context) is y.eval(context)),
+ 'is not': infix(10, lambda context, x, y: x.eval(context) is not y.eval(context)),
'==': infix(10, lambda context, x, y: x.eval(context) == y.eval(context)),
'!=': infix(10, lambda context, x, y: x.eval(context) != y.eval(context)),
'>': infix(10, lambda context, x, y: x.eval(context) > y.eval(context)),
@@ -149,13 +150,16 @@ class IfParser(object):
error_class = ValueError
def __init__(self, tokens):
- # pre-pass necessary to turn 'not','in' into single token
+ # Turn 'is','not' and 'not','in' into single tokens.
l = len(tokens)
mapped_tokens = []
i = 0
while i < l:
token = tokens[i]
- if token == "not" and i + 1 < l and tokens[i + 1] == "in":
+ if token == "is" and i + 1 < l and tokens[i + 1] == "not":
+ token = "is not"
+ i += 1 # skip 'not'
+ elif token == "not" and i + 1 < l and tokens[i + 1] == "in":
token = "not in"
i += 1 # skip 'in'
mapped_tokens.append(self.translate_token(token))