forked from 0x2620/pandora
speedup annotation looksup
This commit is contained in:
parent
39f42aa1dd
commit
a6e120322f
2 changed files with 9 additions and 7 deletions
|
@ -79,8 +79,9 @@ class Annotation(models.Model):
|
||||||
user = models.ForeignKey(User)
|
user = models.ForeignKey(User)
|
||||||
item = models.ForeignKey('item.Item', related_name='annotations')
|
item = models.ForeignKey('item.Item', related_name='annotations')
|
||||||
|
|
||||||
|
public_id = models.CharField(max_length=128, unique=True)
|
||||||
#seconds
|
#seconds
|
||||||
start = models.FloatField(default=-1)
|
start = models.FloatField(default=-1, db_index=True)
|
||||||
end = models.FloatField(default=-1)
|
end = models.FloatField(default=-1)
|
||||||
|
|
||||||
layer = models.ForeignKey(Layer)
|
layer = models.ForeignKey(Layer)
|
||||||
|
@ -100,12 +101,15 @@ class Annotation(models.Model):
|
||||||
else:
|
else:
|
||||||
return self.value
|
return self.value
|
||||||
|
|
||||||
def get_id(self):
|
def save(self, *args, **kwargs):
|
||||||
return '%s/%s' % (self.item.itemId, ox.to32(self.id))
|
if not self.id:
|
||||||
|
super(Annotation, self).save(*args, **kwargs)
|
||||||
|
self.public_id = '%s/%s' % (self.item.itemId, ox.to32(self.id))
|
||||||
|
super(Annotation, self).save(*args, **kwargs)
|
||||||
|
|
||||||
def json(self, layer=False, keys=None):
|
def json(self, layer=False, keys=None):
|
||||||
j = {
|
j = {
|
||||||
'id': self.get_id(),
|
'id': self.public_id,
|
||||||
'user': self.user.username,
|
'user': self.user.username,
|
||||||
'in': self.start,
|
'in': self.start,
|
||||||
'out': self.end,
|
'out': self.end,
|
||||||
|
@ -125,8 +129,6 @@ class Annotation(models.Model):
|
||||||
streams = self.item.streams()
|
streams = self.item.streams()
|
||||||
if streams:
|
if streams:
|
||||||
j['videoRatio'] = streams[0].aspect_ratio
|
j['videoRatio'] = streams[0].aspect_ratio
|
||||||
if 'item' in keys:
|
|
||||||
j['item'] = self.item.itemId
|
|
||||||
return j
|
return j
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
|
|
|
@ -58,7 +58,7 @@ def findAnnotations(request):
|
||||||
qs = qs[query['range'][0]:query['range'][1]]
|
qs = qs[query['range'][0]:query['range'][1]]
|
||||||
response['data']['items'] = [p.json(keys=data['keys']) for p in qs]
|
response['data']['items'] = [p.json(keys=data['keys']) for p in qs]
|
||||||
elif 'position' in query:
|
elif 'position' in query:
|
||||||
ids = [i.get_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'],
|
||||||
'key': query['sort'][0]['key'],
|
'key': query['sort'][0]['key'],
|
||||||
|
|
Loading…
Reference in a new issue