only update clip values after creation

This commit is contained in:
j 2012-03-07 11:36:32 +01:00
parent e33c218c6b
commit e3b5e2a6e7
2 changed files with 18 additions and 16 deletions

View file

@ -35,17 +35,18 @@ class MetaClip:
streams = self.item.streams() streams = self.item.streams()
if streams: if streams:
self.aspect_ratio = streams[0].aspect_ratio 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: 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']: for l in settings.CONFIG['clipLayers']:
setattr(self, l, self.annotations.filter(layer=l).count()>0) setattr(self, l, self.annotations.filter(layer=l).count()>0)
models.Model.save(self, *args, **kwargs) models.Model.save(self, *args, **kwargs)

View file

@ -97,9 +97,10 @@ def findClips(request):
def add(p): def add(p):
ids.append(p.id) ids.append(p.id)
return p.json(keys=keys) 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'] keys = data['keys']
def add_annotations(key, qs, add_layer=False): def add_annotations(key, qs, add_layer=False):
values = ['public_id', 'value', 'clip__public_id'] values = ['public_id', 'value', 'clip__public_id']
if add_layer: if add_layer:
@ -120,12 +121,12 @@ def findClips(request):
i[key].append(l) i[key].append(l)
if response['data']['items']: if response['data']['items']:
if 'annotations' in keys: if 'annotations' in keys:
add_annotations('annotations', aqs = Annotation.objects.filter(layer__in=settings.CONFIG['clipLayers'],
Annotation.objects.filter(layer__in=settings.CONFIG['clipLayers'], clip__in=ids)
clip__in=ids), True) add_annotations('annotations',aqs , True)
for layer in filter(lambda l: l in keys, settings.CONFIG['clipLayers']): for layer in filter(lambda l: l in keys, settings.CONFIG['clipLayers']):
add_annotations(layer, aqs = Annotation.objects.filter(layer=layer, clip__in=ids)
Annotation.objects.filter(layer=layer, clip__in=ids)) add_annotations(layer, aqs)
elif 'position' in query: elif 'position' in query:
qs = order_query(qs, query['sort']) qs = order_query(qs, query['sort'])
ids = [i['public_id'] for i in qs.values('public_id')] ids = [i['public_id'] for i in qs.values('public_id')]