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):