find clipQuery

This commit is contained in:
j 2011-10-19 17:55:29 +02:00
parent ced5d06f89
commit 898aa66509
3 changed files with 32 additions and 15 deletions

View file

@ -144,7 +144,7 @@ class Annotation(models.Model):
'saturation': 'clip__saturation', 'saturation': 'clip__saturation',
'volume': 'clip__volume', 'volume': 'clip__volume',
}.get(field, field)) }.get(field, field))
if layer: if layer or (keys and 'layer' in keys):
j['layer'] = self.layer.name j['layer'] = self.layer.name
if keys: if keys:
_j = {} _j = {}

View file

@ -79,8 +79,11 @@ class Clip(models.Model):
public_layers = [l['id'] public_layers = [l['id']
for l in filter(lambda l: not l.get('private', False), for l in filter(lambda l: not l.get('private', False),
settings.CONFIG['layers'])] 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): for layer in filter(lambda l: l in keys, public_layers):
j[layer] = [a.json(keys=['value'])['value'] j[layer] = [a.json(keys=['id', 'value'])
for a in self.annotations.filter(layer__name=layer)] 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:

View file

@ -25,7 +25,7 @@ import tasks
from archive.models import File, Stream from archive.models import File, Stream
from archive import extract from archive import extract
from annotation.models import Annotation from clip.models import Clip
from api.actions import actions from api.actions import actions
@ -90,10 +90,11 @@ def parse_query(data, user):
if key in data: if key in data:
query[key] = data[key] query[key] = data[key]
query['qs'] = models.Item.objects.find(data, user) query['qs'] = models.Item.objects.find(data, user)
if 'annotations' in data:
query['annotations'] = data['annotations'] if 'clipQuery' in data:
#FIXME: annotations need manager find(data, user) query['clip_qs'] = Clip.objects.find({'query': data['clipQuery']}, user).order_by('start')
query['aqs'] = Annotation.objects.filter(Q(layer__private=False)|Q(user=user)) query['clip_items'] = data['clipQuery'].get('items', 5)
query['clip_keys'] = data['clipQuery'].get('keys', ['id', 'in', 'out', 'annotations'])
#group by only allows sorting by name or number of itmes #group by only allows sorting by name or number of itmes
return query return query
@ -104,6 +105,7 @@ def find(request):
'query': query, 'query': query,
'sort': array, 'sort': array,
'range': array 'range': array
clipQuery: ...
} }
query: query object, more on query syntax at query: query object, more on query syntax at
@ -226,10 +228,16 @@ Positions
r[p] = m.sort.popularity r[p] = m.sort.popularity
else: else:
r[p] = m.json.get(p, '') r[p] = m.json.get(p, '')
if 'annotations' in query: if 'clip_qs' in query:
n = query['annotations'] qs = query['clip_qs'].filter(item=m)
r['annotations'] = [a.json(layer=True) n = qs.count()
for a in query['aqs'].filter(itemID=m.id)[:n]] if n > query['clip_items']:
clips = []
for i in range(0, n, int(n/query['clip_items'])):
clips.append(qs[i])
else:
clips = qs
r['clips'] = [c.json(query['clip_keys']) for c in clips]
return r return r
def only_p(m): def only_p(m):
r = {} r = {}
@ -237,10 +245,16 @@ Positions
m = json.loads(m, object_hook=ox.django.fields.from_json) m = json.loads(m, object_hook=ox.django.fields.from_json)
for p in _p: for p in _p:
r[p] = m.get(p, '') r[p] = m.get(p, '')
if 'annotations' in query: if 'clip_qs' in query:
n = query['annotations'] qs = query['clip_qs'].filter(item__itemId=m['id'])
r['annotations'] = [a.json(layer=True) n = qs.count()
for a in query['aqs'].filter(item__itemId=m['id'])[:n]] if n > query['clip_items']:
clips = []
for i in range(0, n, int(n/query['clip_items'])):
clips.append(qs[i])
else:
clips = qs
r['clips'] = [c.json(query['clip_keys']) for c in clips]
return r return r
qs = qs[query['range'][0]:query['range'][1]] qs = qs[query['range'][0]:query['range'][1]]
#response['data']['items'] = [m.get_json(_p) for m in qs] #response['data']['items'] = [m.get_json(_p) for m in qs]