diff --git a/pandora/item/models.py b/pandora/item/models.py index 09f7f6a97..f0570b937 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -434,7 +434,7 @@ class Item(models.Model): a.public_id = public_id a.save() if sync: - tasks.update_file_paths(self.public_id) + self.update_file_paths() if update_poster: tasks.update_poster(self.public_id) else: @@ -1099,6 +1099,11 @@ class Item(models.Model): else: self.update_facet(key) + def update_file_paths(self): + for f in item.files.all(): + if f.normalize_path() != f.path: + f.save() + def path(self, name=''): h = self.public_id h = (7-len(h))*'0' + h diff --git a/pandora/item/tasks.py b/pandora/item/tasks.py index 614a17c1a..d0076fe20 100644 --- a/pandora/item/tasks.py +++ b/pandora/item/tasks.py @@ -67,9 +67,7 @@ def update_poster(public_id): @task(ignore_results=True, queue='default') def update_file_paths(public_id): item = models.Item.objects.get(public_id=public_id) - for f in item.files.all(): - if f.normalize_path() != f.path: - f.save() + item.update_file_paths() @task(ignore_results=True, queue='default') def update_external(public_id): diff --git a/pandora/person/tasks.py b/pandora/person/tasks.py index 8d65ca644..81a44e54e 100644 --- a/pandora/person/tasks.py +++ b/pandora/person/tasks.py @@ -15,8 +15,8 @@ def update_itemsort(id): @task(ignore_results=True, queue='default') def update_file_paths(id): - from item.models import Item - from item.tasks import update_file_paths + from item.models import Item, ItemFind p = models.Person.objects.get(pk=id) - for i in Item.objects.filter(find__value__icontains=p.name).distinct(): - update_file_paths(i.public_id) + items = ItemFind.objects.filter(key='name', value__icontains=p.name).values('item_id') + for i in Item.objects.filter(id__in=items): + i.update_file_paths()