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