forked from 0x2620/pandora
allow itemkeys to be requested in findClips
This commit is contained in:
parent
f23a480208
commit
be21595733
2 changed files with 12 additions and 10 deletions
|
@ -50,19 +50,18 @@ class Clip(models.Model):
|
|||
|
||||
def json(self, keys=None):
|
||||
j = {}
|
||||
for field in ('id', 'in', 'out', 'created', 'modified',
|
||||
'hue', 'saturation', 'lightness', 'volume'):
|
||||
j[field] = getattr(self, {
|
||||
clip_keys = ('id', 'in', 'out', 'created', 'modified',
|
||||
'hue', 'saturation', 'lightness', 'volume')
|
||||
for key in clip_keys:
|
||||
j[key] = getattr(self, {
|
||||
'id': 'public_id',
|
||||
'in': 'start',
|
||||
'out': 'end',
|
||||
}.get(field, field))
|
||||
}.get(key, key))
|
||||
if keys:
|
||||
_j = {}
|
||||
for key in keys:
|
||||
if key in j:
|
||||
_j[key] = j[key]
|
||||
j = _j
|
||||
for key in j.keys():
|
||||
if key not in keys:
|
||||
del j[key]
|
||||
if 'videoRatio' in keys:
|
||||
streams = self.item.streams()
|
||||
if streams:
|
||||
|
@ -73,6 +72,9 @@ class Clip(models.Model):
|
|||
for layer in filter(lambda l: l in keys, public_layers):
|
||||
j[layer] = [a.json(keys=['value'])['value']
|
||||
for a in self.annotations.filter(layer__name=layer)]
|
||||
for key in keys:
|
||||
if key not in clip_keys and key not in j:
|
||||
j[key] = self.item.get(key)
|
||||
return j
|
||||
|
||||
def __unicode__(self):
|
||||
|
|
|
@ -71,7 +71,7 @@ def findClips(request):
|
|||
query = parse_query(data, request.user)
|
||||
qs = order_query(query['qs'], query['sort'])
|
||||
if 'keys' in data:
|
||||
qs = qs[query['range'][0]:query['range'][1]]
|
||||
qs = qs.select_related()[query['range'][0]:query['range'][1]]
|
||||
response['data']['items'] = [p.json(keys=data['keys']) for p in qs]
|
||||
elif 'position' in query:
|
||||
ids = [i.public_id for i in qs]
|
||||
|
|
Loading…
Reference in a new issue