forked from 0x2620/pandora
Merge remote-tracking branch 'wjt/get-layers-only-entity-name'
(fixes #2913)
This commit is contained in:
commit
34747c0fd7
2 changed files with 17 additions and 19 deletions
|
@ -138,8 +138,7 @@ class Annotation(models.Model):
|
|||
|
||||
findvalue = self.value
|
||||
try:
|
||||
l = self.get_layer()
|
||||
if l['type'] == 'entity':
|
||||
if layer['type'] == 'entity':
|
||||
findvalue = self.get_entity().name
|
||||
except:
|
||||
pass
|
||||
|
@ -210,19 +209,15 @@ class Annotation(models.Model):
|
|||
def _get_entity_json(self, user=None, entity_cache=None):
|
||||
"""When serializing many annotations pointing to the same entity, it is expensive to
|
||||
repeatedly look up and serialize the same entity.
|
||||
|
||||
TODO: if Entity were a (nullable) foreign key of Annotation, we could just:
|
||||
|
||||
prefetch_related('entity', 'entity__user', 'entity__documents')
|
||||
|
||||
before serializing the annotations, which would make self.entity.json(user=user) cheap and
|
||||
all this unnecessary.
|
||||
"""
|
||||
from entity.models import Entity
|
||||
|
||||
if entity_cache is not None and self.value in entity_cache:
|
||||
return entity_cache[self.value]
|
||||
|
||||
entity = self.get_entity()
|
||||
entity_json = entity.json(user=user)
|
||||
id = ox.fromAZ(self.value)
|
||||
entity = Entity.objects.filter(id=id).only('name').get()
|
||||
entity_json = entity.json(keys=['id', 'name'])
|
||||
value = entity.annotation_value()
|
||||
|
||||
if entity_cache is not None:
|
||||
|
@ -295,10 +290,13 @@ class Annotation(models.Model):
|
|||
value = getattr(self.item.sort, key)
|
||||
if value != None:
|
||||
j[key] = value
|
||||
subtitles = get_by_key(settings.CONFIG['layers'], 'isSubtitles', True)
|
||||
if subtitles:
|
||||
if 'id' in j and self.layer == subtitles['id'] and not self.value:
|
||||
|
||||
# Items without any real subtitles are given a dummy 5-second subtitle
|
||||
# every minute to ensure that they have at least *some* clips. Treat
|
||||
# them specially. See Item.add_empty_clips
|
||||
if l.get('isSubtitles') and 'id' in j and not self.value:
|
||||
del j['id']
|
||||
|
||||
return j
|
||||
|
||||
def __unicode__(self):
|
||||
|
|
|
@ -168,8 +168,8 @@ class Entity(models.Model):
|
|||
elif key == 'sortName':
|
||||
response[key] = self.name_sort
|
||||
elif key == 'documents':
|
||||
response[key] = [ox.toAZ(d['id'])
|
||||
for d in self.documents.all().values('id').order_by('documentproperties__index')]
|
||||
response[key] = [ox.toAZ(id_)
|
||||
for id_, in self.documentproperties.order_by('index').values_list('document_id')]
|
||||
elif key in self.data:
|
||||
response[key] = self.data[key]
|
||||
return response
|
||||
|
|
Loading…
Reference in a new issue