diff --git a/pandora/clip/models.py b/pandora/clip/models.py index 34814453e..656170fda 100644 --- a/pandora/clip/models.py +++ b/pandora/clip/models.py @@ -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): diff --git a/pandora/clip/views.py b/pandora/clip/views.py index 05a3884b7..cd5aefae9 100644 --- a/pandora/clip/views.py +++ b/pandora/clip/views.py @@ -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]