merge
This commit is contained in:
commit
c3fb0b9b87
3 changed files with 32 additions and 15 deletions
|
@ -32,8 +32,8 @@ def create_or_update_layer(data):
|
||||||
|
|
||||||
class Layer(models.Model):
|
class Layer(models.Model):
|
||||||
|
|
||||||
class Meta:
|
#class Meta:
|
||||||
ordering = ('position', )
|
# ordering = ('position', )
|
||||||
|
|
||||||
enabled = models.BooleanField(default=True)
|
enabled = models.BooleanField(default=True)
|
||||||
|
|
||||||
|
|
|
@ -79,17 +79,6 @@ class Clip(models.Model):
|
||||||
for key in j.keys():
|
for key in j.keys():
|
||||||
if key not in keys:
|
if key not in keys:
|
||||||
del j[key]
|
del j[key]
|
||||||
public_layers = [l['id']
|
|
||||||
for l in filter(lambda l: not l.get('private', False),
|
|
||||||
settings.CONFIG['layers'])]
|
|
||||||
if 'annotations' in keys:
|
|
||||||
j['annotations'] = [a.json(keys=['value', 'id', 'layer'])
|
|
||||||
for a in self.annotations.filter(layer__name__in=public_layers).select_related()]
|
|
||||||
|
|
||||||
for layer in filter(lambda l: l in keys, public_layers):
|
|
||||||
j[layer] = [a.json(keys=['id', 'value'])
|
|
||||||
for a in self.annotations.filter(layer__name=layer)]
|
|
||||||
|
|
||||||
for key in keys:
|
for key in keys:
|
||||||
if key not in clip_keys and key not in j:
|
if key not in clip_keys and key not in j:
|
||||||
value = self.item.get(key)
|
value = self.item.get(key)
|
||||||
|
|
|
@ -75,12 +75,39 @@ def findClips(request):
|
||||||
response = json_response()
|
response = json_response()
|
||||||
|
|
||||||
query = parse_query(data, request.user)
|
query = parse_query(data, request.user)
|
||||||
qs = order_query(query['qs'], query['sort'])
|
qs = query['qs']
|
||||||
if 'keys' in data:
|
if 'keys' in data:
|
||||||
|
qs = order_query(qs, query['sort'])
|
||||||
qs = qs[query['range'][0]:query['range'][1]]
|
qs = qs[query['range'][0]:query['range'][1]]
|
||||||
qs = qs.select_related()
|
qs = qs.select_related('item__sort')
|
||||||
response['data']['items'] = [p.json(keys=data['keys']) for p in qs]
|
response['data']['items'] = [p.json(keys=data['keys']) for p in qs]
|
||||||
|
from django.conf import settings
|
||||||
|
from annotation.models import Annotation
|
||||||
|
|
||||||
|
keys = data['keys']
|
||||||
|
public_layers = [l['id']
|
||||||
|
for l in filter(lambda l: not l.get('private', False),
|
||||||
|
settings.CONFIG['layers'])]
|
||||||
|
|
||||||
|
def merge_annotations(layer, qs):
|
||||||
|
for a in qs.values('public_id', 'value', 'clip__public_id'):
|
||||||
|
for i in response['data']['items']:
|
||||||
|
if i['id'] == a['clip__public_id']:
|
||||||
|
if not i[layer]:
|
||||||
|
i[layer] = []
|
||||||
|
i[layer].append({
|
||||||
|
'id': a['public_id'],
|
||||||
|
'value': a['value'],
|
||||||
|
})
|
||||||
|
|
||||||
|
if 'annotations' in keys:
|
||||||
|
merge_annotations('annotations',
|
||||||
|
Annotation.objects.filter(layer__name__in=public_layers, clip__in=qs))
|
||||||
|
for layer in filter(lambda l: l in keys, public_layers):
|
||||||
|
merge_annotations(layer,
|
||||||
|
Annotation.objects.filter(layer__name=layer, clip__in=qs))
|
||||||
elif 'position' in query:
|
elif 'position' in query:
|
||||||
|
qs = order_query(qs, query['sort'])
|
||||||
ids = [i.public_id for i in qs]
|
ids = [i.public_id for i in qs]
|
||||||
data['conditions'] = data['conditions'] + {
|
data['conditions'] = data['conditions'] + {
|
||||||
'value': data['position'],
|
'value': data['position'],
|
||||||
|
@ -92,6 +119,7 @@ def findClips(request):
|
||||||
if qs.count() > 0:
|
if qs.count() > 0:
|
||||||
response['data']['position'] = utils.get_positions(ids, [qs[0].itemId])[0]
|
response['data']['position'] = utils.get_positions(ids, [qs[0].itemId])[0]
|
||||||
elif 'positions' in data:
|
elif 'positions' in data:
|
||||||
|
qs = order_query(qs, query['sort'])
|
||||||
ids = [i.public_id for i in qs]
|
ids = [i.public_id for i in qs]
|
||||||
response['data']['positions'] = utils.get_positions(ids, data['positions'])
|
response['data']['positions'] = utils.get_positions(ids, data['positions'])
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue