From 83013bbe5ecc2cbae3616e723fb8d8052e1f1ecf Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Wed, 26 Aug 2015 19:42:03 +0200 Subject: [PATCH] Update items when entities are renamed (fixes #2825) --- pandora/annotation/tasks.py | 4 ++-- pandora/entity/models.py | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/pandora/annotation/tasks.py b/pandora/annotation/tasks.py index 1d7495c8..824b7e79 100644 --- a/pandora/annotation/tasks.py +++ b/pandora/annotation/tasks.py @@ -105,11 +105,11 @@ def add_annotations(data): return True @task(ignore_results=True, queue='default') -def update_item(id): +def update_item(id, force=False): from item.models import Item from clip.models import Clip 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 Clip.objects.filter(item__id=a.item.id, annotations__id=None).delete() #update facets if needed diff --git a/pandora/entity/models.py b/pandora/entity/models.py index 8a5bfa17..456e42d2 100644 --- a/pandora/entity/models.py +++ b/pandora/entity/models.py @@ -230,11 +230,20 @@ class Entity(models.Model): def update_annotations(self): import annotation.models + import annotation.tasks + entity_layers = [l['id'] for l in settings.CONFIG['layers'] if l['type'] == 'entity'] if entity_layers: 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() + items[a.item.id] = a.id + for id in items.values(): + annotation.tasks.update_item.delay(id, True) class DocumentProperties(models.Model):