Update items when entities are renamed (fixes #2825)

This commit is contained in:
j 2015-08-26 19:42:03 +02:00
parent 944fe1a9dd
commit 83013bbe5e
2 changed files with 12 additions and 3 deletions

View file

@ -105,11 +105,11 @@ def add_annotations(data):
return True return True
@task(ignore_results=True, queue='default') @task(ignore_results=True, queue='default')
def update_item(id): def update_item(id, force=False):
from item.models import Item from item.models import Item
from clip.models import Clip from clip.models import Clip
a = models.Annotation.objects.get(pk=id) a = models.Annotation.objects.get(pk=id)
if a.modified >= a.item.annotations.order_by('-modified')[0].modified: if force or a.modified >= a.item.annotations.order_by('-modified')[0].modified:
#cleanup orphaned clips #cleanup orphaned clips
Clip.objects.filter(item__id=a.item.id, annotations__id=None).delete() Clip.objects.filter(item__id=a.item.id, annotations__id=None).delete()
#update facets if needed #update facets if needed

View file

@ -230,11 +230,20 @@ class Entity(models.Model):
def update_annotations(self): def update_annotations(self):
import annotation.models import annotation.models
import annotation.tasks
entity_layers = [l['id'] for l in settings.CONFIG['layers'] if l['type'] == 'entity'] entity_layers = [l['id'] for l in settings.CONFIG['layers'] if l['type'] == 'entity']
if entity_layers: if entity_layers:
with transaction.commit_on_success(): with transaction.commit_on_success():
for a in annotation.models.Annotation.objects.filter(layer__in=entity_layers, value=self.get_id()): items = {}
for a in annotation.models.Annotation.objects.filter(
layer__in=entity_layers,
value=self.get_id()
):
a.save() a.save()
items[a.item.id] = a.id
for id in items.values():
annotation.tasks.update_item.delay(id, True)
class DocumentProperties(models.Model): class DocumentProperties(models.Model):