Update items when entities are renamed (fixes #2825)
This commit is contained in:
parent
944fe1a9dd
commit
83013bbe5e
2 changed files with 12 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -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):
|
||||
|
||||
|
|
Loading…
Reference in a new issue