mirror of
https://github.com/ansible/awx.git
synced 2026-03-24 04:15:02 -02:30
support > 2 sequential and, also or
* Fixed a bug in the fact search language parser where it would not loop over all the <and, or> operations. The result, we can support (a=b or a=c or a=d) also support (a=b and b=b and c=b)
This commit is contained in:
@@ -453,10 +453,14 @@ class DynamicFilterField(models.TextField):
|
|||||||
|
|
||||||
class BoolBinOp(object):
|
class BoolBinOp(object):
|
||||||
def __init__(self, t):
|
def __init__(self, t):
|
||||||
self.left = t[0][0].result
|
self.result = None
|
||||||
self.right = t[0][2].result
|
i = 2
|
||||||
|
while i < len(t[0]):
|
||||||
self.result = self.execute_logic(self.left, self.right)
|
if not self.result:
|
||||||
|
self.result = t[0][0].result
|
||||||
|
right = t[0][i].result
|
||||||
|
self.result = self.execute_logic(self.result, right)
|
||||||
|
i += 2
|
||||||
|
|
||||||
|
|
||||||
class BoolAnd(BoolBinOp):
|
class BoolAnd(BoolBinOp):
|
||||||
@@ -508,7 +512,7 @@ class DynamicFilterField(models.TextField):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
res = boolExpr.parseString('(' + filter_string + ')')
|
res = boolExpr.parseString('(' + filter_string + ')')
|
||||||
except:
|
except Exception:
|
||||||
raise RuntimeError(u"Invalid query %s" % filter_string_raw)
|
raise RuntimeError(u"Invalid query %s" % filter_string_raw)
|
||||||
|
|
||||||
if len(res) > 0:
|
if len(res) > 0:
|
||||||
|
|||||||
@@ -49,7 +49,8 @@ class TestDynamicFilterFieldFilterStringToQ():
|
|||||||
('a=b or c=d', Q(**{u"a": u"b"}) | Q(**{u"c": u"d"})),
|
('a=b or c=d', Q(**{u"a": u"b"}) | Q(**{u"c": u"d"})),
|
||||||
('(a=b and c=d) or (e=f)', (Q(**{u"a": u"b"}) & Q(**{u"c": u"d"})) | (Q(**{u"e": u"f"}))),
|
('(a=b and c=d) or (e=f)', (Q(**{u"a": u"b"}) & Q(**{u"c": u"d"})) | (Q(**{u"e": u"f"}))),
|
||||||
('(a=b and not c=d) or not (e=f)', (Q(**{u"a": u"b"}) & ~Q(**{u"c": u"d"})) | (~Q(**{u"e": u"f"}))),
|
('(a=b and not c=d) or not (e=f)', (Q(**{u"a": u"b"}) & ~Q(**{u"c": u"d"})) | (~Q(**{u"e": u"f"}))),
|
||||||
('(a=b) and not (c=d or (e=f and (g=h or i=j))) or (y=z)', Q(**{u"a": u"b"}) & ~(Q(**{u"c": u"d"}) | (Q(**{u"e": u"f"}) & (Q(**{u"g": u"h"}) | Q(**{u"i": u"j"})))) | Q(**{u"y": u"z"}))
|
('(a=b) and not (c=d or (e=f and (g=h or i=j))) or (y=z)', Q(**{u"a": u"b"}) & ~(Q(**{u"c": u"d"}) | (Q(**{u"e": u"f"}) & (Q(**{u"g": u"h"}) | Q(**{u"i": u"j"})))) | Q(**{u"y": u"z"})),
|
||||||
|
('a=b or a=d or a=e or a=z and b=h and b=i and b=j and b=k', Q(**{u"a": u"b"}) | Q(**{u"a": u"d"}) | Q(**{u"a": u"e"}) | Q(**{u"a": u"z"}) & Q(**{u"b": u"h"}) & Q(**{u"b": u"i"}) & Q(**{u"b": u"j"}) & Q(**{u"b": u"k"}))
|
||||||
])
|
])
|
||||||
def test_boolean_parenthesis(self, filter_string, q_expected):
|
def test_boolean_parenthesis(self, filter_string, q_expected):
|
||||||
q = DynamicFilterField.filter_string_to_q(filter_string)
|
q = DynamicFilterField.filter_string_to_q(filter_string)
|
||||||
|
|||||||
Reference in New Issue
Block a user