From 99e459133714dfab3c8220c2fd21e1978762840b Mon Sep 17 00:00:00 2001 From: j Date: Wed, 14 Nov 2018 15:36:37 +0000 Subject: [PATCH] support nested & conditions --- pandora/clip/managers.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pandora/clip/managers.py b/pandora/clip/managers.py index 7998bf03..d69fb7c6 100644 --- a/pandora/clip/managers.py +++ b/pandora/clip/managers.py @@ -126,6 +126,15 @@ def parseConditions(conditions, operator, user): return conn return None +def flatten_conditions(conditions): + conditions_ = [] + for c in conditions: + if 'conditions' in c: + conditions_ += flatten_conditions(c['conditions']) + else: + conditions_.append(c) + return conditions_ + class ClipManager(Manager): def get_query_set(self): @@ -135,7 +144,8 @@ class ClipManager(Manager): layer_ids = [k['id'] for k in settings.CONFIG['layers']] keys = layer_ids + ['annotations', 'text', '*'] conditions = data.get('query', {}).get('conditions', []) - conditions = list(filter(lambda c: c['key'] in keys, conditions)) + conditions = flatten_conditions(conditions) + conditions = list(filter(lambda c: c.get('key') in keys, conditions)) operator = data.get('query', {}).get('operator', '&') def parse(condition):