forked from 0x2620/pandora
fix & queries with multiple item keys
This commit is contained in:
parent
683e4b2780
commit
9bab85e00a
1 changed files with 14 additions and 8 deletions
|
@ -229,17 +229,20 @@ def parseConditions(conditions, operator, user):
|
||||||
if 'conditions' in condition:
|
if 'conditions' in condition:
|
||||||
q = parseConditions(condition['conditions'],
|
q = parseConditions(condition['conditions'],
|
||||||
condition.get('operator', '&'), user)
|
condition.get('operator', '&'), user)
|
||||||
if q:
|
if isinstance(q, list):
|
||||||
|
conn += q
|
||||||
|
elif q:
|
||||||
conn.append(q)
|
conn.append(q)
|
||||||
else:
|
else:
|
||||||
conn.append(parseCondition(condition, user))
|
conn.append(parseCondition(condition, user))
|
||||||
if conn:
|
if conn:
|
||||||
|
if operator == '|':
|
||||||
q = conn[0]
|
q = conn[0]
|
||||||
for c in conn[1:]:
|
for c in conn[1:]:
|
||||||
if operator == '|':
|
|
||||||
q = q | c
|
q = q | c
|
||||||
|
q = [q]
|
||||||
else:
|
else:
|
||||||
q = q & c
|
q = conn
|
||||||
return q
|
return q
|
||||||
return Q()
|
return Q()
|
||||||
|
|
||||||
|
@ -269,7 +272,8 @@ class ItemManager(Manager):
|
||||||
conditions = parseConditions(data['query']['conditions'],
|
conditions = parseConditions(data['query']['conditions'],
|
||||||
data['query'].get('operator', '&'),
|
data['query'].get('operator', '&'),
|
||||||
user)
|
user)
|
||||||
qs = qs.filter(conditions)
|
for c in conditions:
|
||||||
|
qs = qs.filter(c)
|
||||||
else:
|
else:
|
||||||
qs = qs.filter(id__in=lqs[0].items.all())
|
qs = qs.filter(id__in=lqs[0].items.all())
|
||||||
return qs
|
return qs
|
||||||
|
@ -302,7 +306,9 @@ class ItemManager(Manager):
|
||||||
conditions = parseConditions(data.get('query', {}).get('conditions', []),
|
conditions = parseConditions(data.get('query', {}).get('conditions', []),
|
||||||
data.get('query', {}).get('operator', '&'),
|
data.get('query', {}).get('operator', '&'),
|
||||||
user)
|
user)
|
||||||
qs = qs.filter(conditions)
|
for c in conditions:
|
||||||
|
qs = qs.filter(c)
|
||||||
|
|
||||||
#FIXME: can this be avoided? needed for grid/accessed/foo
|
#FIXME: can this be avoided? needed for grid/accessed/foo
|
||||||
qs = qs.distinct()
|
qs = qs.distinct()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue