findEntities: fix negated conditions, fixes #2876

This commit is contained in:
Will Thompson 2016-01-27 12:25:42 +00:00 committed by j
parent cdaa50c4d3
commit 6008f3b44e

View file

@ -27,14 +27,18 @@ def parseCondition(condition, user, item=None):
v = condition['value']
op = condition.get('operator')
find_key = None
if not op:
op = '='
if op.startswith('!'):
op = op[1:]
exclude = True
return ~buildCondition(k, op[1:], v)
else:
exclude = False
return buildCondition(k, op, v)
def buildCondition(k, op, v):
find_key = None
if k == 'id':
v = ox.fromAZ(v)
return Q(**{k: v})
@ -55,16 +59,10 @@ def parseCondition(condition, user, item=None):
}.get(op, '__icontains'))
key = str(key)
if find_key:
if exclude:
q = Q(**{'find__key': find_key, key: v})
else:
q = Q(**{'find__key': find_key, key: v})
return Q(**{'find__key': find_key, key: v})
else:
if exclude:
q = ~Q(**{key: v})
else:
q = Q(**{key: v})
return q
return Q(**{key: v})
def parseConditions(conditions, operator, user, item=None):
'''