From 0c99cbfaac158faa31c888ff20120ee2d1345624 Mon Sep 17 00:00:00 2001 From: j Date: Thu, 9 Aug 2018 10:53:23 +0100 Subject: [PATCH] fix findClips to return clips with annotations matching all conditions --- pandora/clip/managers.py | 28 ++++++++++++++++------------ pandora/clip/views.py | 3 ++- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/pandora/clip/managers.py b/pandora/clip/managers.py index e1fa7591..f4c92416 100644 --- a/pandora/clip/managers.py +++ b/pandora/clip/managers.py @@ -116,13 +116,13 @@ def parseConditions(conditions, operator, user): else: conn.append(parseCondition(condition, user)) if conn: - q = conn[0] - for c in conn[1:]: - if operator == '|': + if operator == '|': + q = conn[0] + for c in conn[1:]: q = q | c - else: - q = q & c - return q + return [q] + else: + return conn return None class ClipManager(Manager): @@ -149,12 +149,15 @@ class ClipManager(Manager): conditions = [parse(c) for c in conditions] if conditions: - q = conditions[0] - for c in conditions[1:]: - if operator == '|': + # always make an any query, + # since & is for intersection in clip not intersection in annotation + if operator == '|' or operator == '&': + q = conditions[0] + for c in conditions[1:]: q = q | c - else: - q = q & c + return [q] + else: + return conditions return q return None @@ -187,7 +190,8 @@ class ClipManager(Manager): data.get('query', {}).get('operator', '&'), user) if conditions: - qs = qs.filter(conditions) + for condition in conditions: + qs = qs.filter(condition) qs = qs.distinct() diff --git a/pandora/clip/views.py b/pandora/clip/views.py index dd5297cf..b37427c2 100644 --- a/pandora/clip/views.py +++ b/pandora/clip/views.py @@ -117,7 +117,8 @@ def findClips(request, data): def add_annotations(key, qs, add_layer=False): values = ['public_id', 'layer', 'value', 'clip_id'] if query['filter']: - qs = qs.filter(query['filter']) + for limit in query['filter']: + qs = qs.filter(limit) for i in response['data']['items']: if not key in i: i[key] = []