From 16f1dbca93ae9cc81f7d3e6251b1c982ded9a7c1 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Mon, 17 Nov 2014 14:12:29 +0000 Subject: [PATCH] fix findClips for layers no in clipLayers --- pandora/clip/managers.py | 12 +++++++----- pandora/clip/models.py | 10 +++++----- pandora/clip/views.py | 7 ++++--- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/pandora/clip/managers.py b/pandora/clip/managers.py index 86827659a..2e8105c29 100644 --- a/pandora/clip/managers.py +++ b/pandora/clip/managers.py @@ -7,7 +7,7 @@ from django.conf import settings from ox.django.query import QuerySet -from item.utils import decode_id +from item.utils import decode_id, get_by_id def parseCondition(condition, user): @@ -38,7 +38,7 @@ def parseCondition(condition, user): op = condition.get('operator') if not op: op = '' - if k in settings.CONFIG.get('clipLayers', []): + if get_by_id(settings.CONFIG['layers'], k): return parseCondition({'key': 'annotations__findvalue', 'value': v, 'operator': op}, user) \ @@ -144,7 +144,8 @@ class ClipManager(Manager): return QuerySet(self.model) def filter_annotations(self, data, user): - keys = settings.CONFIG['clipLayers'] + ['annotations', 'text', '*'] + layer_ids = [k['id'] for k in settings.CONFIG['layers']] + keys = layer_ids + ['annotations', 'text', '*'] conditions = data.get('query', {}).get('conditions', []) conditions = filter(lambda c: c['key'] in keys, conditions) operator = data.get('query', {}).get('operator', '&') @@ -163,7 +164,7 @@ class ClipManager(Manager): if isinstance(v, unicode): v = unicodedata.normalize('NFKD', v).lower() q = Q(**{key: v}) - if condition['key'] in settings.CONFIG['clipLayers']: + if condition['key'] in layer_ids: q = q & Q(layer=condition['key']) return q conditions = map(parse, conditions) @@ -208,7 +209,8 @@ class ClipManager(Manager): if conditions: qs = qs.filter(conditions) if 'keys' in data: - for l in filter(lambda k: k in settings.CONFIG['clipLayers'], data['keys']): + layer_ids = [k['id'] for k in settings.CONFIG['layers']] + for l in filter(lambda k: k in layer_ids, data['keys']): qs = qs.filter(**{l: True}) #anonymous can only see public clips if not user or user.is_anonymous(): diff --git a/pandora/clip/models.py b/pandora/clip/models.py index d44d0dd06..2730164cf 100644 --- a/pandora/clip/models.py +++ b/pandora/clip/models.py @@ -49,7 +49,7 @@ class MetaClip: else: self.sortvalue = None self.findvalue = '\n'.join(filter(None, [a.findvalue for a in self.annotations.all()])) - for l in settings.CONFIG['clipLayers']: + for l in [k['id'] for k in settings.CONFIG['layers']]: setattr(self, l, self.annotations.filter(layer=l).count()>0) models.Model.save(self, *args, **kwargs) @@ -73,11 +73,11 @@ class MetaClip: del j[key] #needed here to make item find with clips work if 'annotations' in keys: - annotations = self.annotations.filter(layer__in=settings.CONFIG['clipLayers']) + #annotations = self.annotations.filter(layer__in=settings.CONFIG['clipLayers']) + annotations = self.annotations.all() if qs: annotations = annotations.filter(qs) - j['annotations'] = [a.json(keys=['value', 'id', 'layer']) - for a in annotations] + j['annotations'] = [a.json(keys=['value', 'id', 'layer']) for a in annotations] if 'layers' in keys: j['layers'] = self.get_layers() if 'cuts' in keys: @@ -184,7 +184,7 @@ attrs = { 'sortvalue': models.CharField(max_length=1000, null=True, db_index=True), 'findvalue': models.TextField(null=True, db_index=settings.DB_GIN_TRGM), } -for name in settings.CONFIG['clipLayers']: +for name in [k['id'] for k in settings.CONFIG['layers']]: attrs[name] = models.BooleanField(default=False, db_index=True) Clip = type('Clip', (MetaClip,models.Model), attrs) diff --git a/pandora/clip/views.py b/pandora/clip/views.py index ccacb4f8b..328ca5f7a 100644 --- a/pandora/clip/views.py +++ b/pandora/clip/views.py @@ -102,8 +102,8 @@ def findClips(request, data): qs = qs[query['range'][0]:query['range'][1]] ids = [] - keys = filter(lambda k: k not in settings.CONFIG['clipLayers'] + ['annotations'], - data['keys']) + layer_ids = [k['id'] for k in settings.CONFIG['layers']] + keys = filter(lambda k: k not in layer_ids + ['annotations'], data['keys']) if filter(lambda k: k not in models.Clip.clip_keys, keys): qs = qs.select_related('sort') @@ -144,7 +144,8 @@ def findClips(request, data): aqs = Annotation.objects.filter(layer__in=settings.CONFIG['clipLayers'], clip__in=ids) add_annotations('annotations',aqs , True) - for layer in filter(lambda l: l in keys, settings.CONFIG['clipLayers']): + layer_ids = [k['id'] for k in settings.CONFIG['layers']] + for layer in filter(lambda l: l in keys, layer_ids): aqs = Annotation.objects.filter(layer=layer, clip__in=ids) add_annotations(layer, aqs) elif 'position' in query: