mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #26479 -- Added 'is not' operator to the if tag.
This commit is contained in:
committed by
Tim Graham
parent
c10db4bd1b
commit
c16b9dd8e0
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user