slightly faster json serialization of annotations
This commit is contained in:
parent
f3fdded07d
commit
819181726a
1 changed files with 16 additions and 16 deletions
|
@ -213,20 +213,17 @@ class Annotation(models.Model):
|
||||||
'duration', 'layer', 'item', 'videoRatio', 'languages',
|
'duration', 'layer', 'item', 'videoRatio', 'languages',
|
||||||
'entity', 'event', 'place'
|
'entity', 'event', 'place'
|
||||||
)
|
)
|
||||||
|
_clip_keys = ('hue', 'lightness', 'saturation', 'volume')
|
||||||
def json(self, layer=False, keys=None, user=None):
|
def json(self, layer=False, keys=None, user=None):
|
||||||
j = {
|
j = {
|
||||||
'user': self.user.username,
|
'user': self.user.username,
|
||||||
|
'id': self.public_id,
|
||||||
|
'in': self.start,
|
||||||
|
'out': self.end,
|
||||||
|
'value': self.value,
|
||||||
|
'created': self.created,
|
||||||
|
'modified': self.modified,
|
||||||
}
|
}
|
||||||
for key in ('id', 'in', 'out', 'value', 'created', 'modified'):
|
|
||||||
j[key] = getattr(self, {
|
|
||||||
'hue': 'clip__hue',
|
|
||||||
'id': 'public_id',
|
|
||||||
'in': 'start',
|
|
||||||
'lightness': 'clip__lightness',
|
|
||||||
'out': 'end',
|
|
||||||
'saturation': 'clip__saturation',
|
|
||||||
'volume': 'clip__volume',
|
|
||||||
}.get(key, key))
|
|
||||||
j['duration'] = abs(j['out'] - j['in'])
|
j['duration'] = abs(j['out'] - j['in'])
|
||||||
if user:
|
if user:
|
||||||
j['editable'] = self.editable(user)
|
j['editable'] = self.editable(user)
|
||||||
|
@ -268,7 +265,10 @@ class Annotation(models.Model):
|
||||||
if streams:
|
if streams:
|
||||||
j['videoRatio'] = streams[0].aspect_ratio
|
j['videoRatio'] = streams[0].aspect_ratio
|
||||||
for key in keys:
|
for key in keys:
|
||||||
if key not in self.annotation_keys and key not in j:
|
if key not in j:
|
||||||
|
if key in self._clip_keys:
|
||||||
|
j[key] = getattr(self.clip, key)
|
||||||
|
elif key not in self.annotation_keys:
|
||||||
value = self.item.get(key) or self.item.json.get(key)
|
value = self.item.get(key) or self.item.json.get(key)
|
||||||
if not value and hasattr(self.item.sort, key):
|
if not value and hasattr(self.item.sort, key):
|
||||||
value = getattr(self.item.sort, key)
|
value = getattr(self.item.sort, key)
|
||||||
|
|
Loading…
Reference in a new issue