update item sort after changing person sort value, fixes #30

This commit is contained in:
j 2012-02-15 21:31:24 +05:30
parent 2cf7c56115
commit 6bdbd729a7
2 changed files with 20 additions and 1 deletions

View file

@ -13,7 +13,7 @@ from item import utils
import item.models
import managers
import tasks
def get_name_sort(name):
name = unicodedata.normalize('NFKD', name).strip()
@ -51,6 +51,9 @@ class Person(models.Model):
self.sortsortname = utils.sort_string(self.sortname)
self.numberofnames = len(self.name.split(' '))
super(Person, self).save(*args, **kwargs)
tasks.update_itemsort.delay(self.id)
def update_itemsort(self):
item.models.Facet.objects.filter(
key__in=item.models.Item.person_keys + ['name'],
value=self.name
@ -59,6 +62,11 @@ class Person(models.Model):
).update(
sortvalue=self.sortname
)
for i in item.models.Item.objects.filter(facets__in=item.models.Facet.objects.filter(
key__in=item.models.Item.person_keys + ['name'],
value=self.name)
).distinct():
i.update_sort()
def get_or_create(model, name, imdbId=None):
if imdbId:

11
pandora/person/tasks.py Normal file
View file

@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
from celery.task import task
import models
@task(ignore_resulsts=True, queue='default')
def update_itemsort(id):
p = models.Person.objects.get(pk=id)
p.update_itemsort()