From e3b5e2a6e795522ea31ec8d567b8eeea64bfc793 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Wed, 7 Mar 2012 11:36:32 +0100 Subject: [PATCH] only update clip values after creation --- pandora/clip/models.py | 21 +++++++++++---------- pandora/clip/views.py | 13 +++++++------ 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/pandora/clip/models.py b/pandora/clip/models.py index 8bf60aae..d4ced3a2 100644 --- a/pandora/clip/models.py +++ b/pandora/clip/models.py @@ -35,17 +35,18 @@ class MetaClip: streams = self.item.streams() if streams: self.aspect_ratio = streams[0].aspect_ratio - sortvalue = '' - for l in settings.CONFIG['clipLayers']: - sortvalue += ''.join(filter(lambda s: s, - [a.sortvalue - for a in self.annotations.filter(layer=l).order_by('sortvalue')])) - if sortvalue: - self.sortvalue = sortvalue[:900] - else: - self.sortvalue = None - self.findvalue = '\n'.join(filter(None, [a.findvalue for a in self.annotations.all()])) if self.id: + sortvalue = '' + if self.id: + for l in settings.CONFIG['clipLayers']: + sortvalue += ''.join(filter(lambda s: s, + [a.sortvalue + for a in self.annotations.filter(layer=l).order_by('sortvalue')])) + if sortvalue: + self.sortvalue = sortvalue[:900] + else: + self.sortvalue = None + self.findvalue = '\n'.join(filter(None, [a.findvalue for a in self.annotations.all()])) for l in settings.CONFIG['clipLayers']: setattr(self, l, self.annotations.filter(layer=l).count()>0) models.Model.save(self, *args, **kwargs) diff --git a/pandora/clip/views.py b/pandora/clip/views.py index 99f8dbd6..28e6df91 100644 --- a/pandora/clip/views.py +++ b/pandora/clip/views.py @@ -97,9 +97,10 @@ def findClips(request): def add(p): ids.append(p.id) return p.json(keys=keys) - response['data']['items'] = [add(p) for p in qs] + response['data']['items'] = [add(p) for p in qs] keys = data['keys'] + def add_annotations(key, qs, add_layer=False): values = ['public_id', 'value', 'clip__public_id'] if add_layer: @@ -120,12 +121,12 @@ def findClips(request): i[key].append(l) if response['data']['items']: if 'annotations' in keys: - add_annotations('annotations', - Annotation.objects.filter(layer__in=settings.CONFIG['clipLayers'], - clip__in=ids), True) + 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']): - add_annotations(layer, - Annotation.objects.filter(layer=layer, clip__in=ids)) + aqs = Annotation.objects.filter(layer=layer, clip__in=ids) + add_annotations(layer, aqs) elif 'position' in query: qs = order_query(qs, query['sort']) ids = [i['public_id'] for i in qs.values('public_id')]