update clip ids on item id change

This commit is contained in:
j 2011-10-25 12:57:31 +02:00
parent d023219359
commit 1af3139e16

View file

@ -251,6 +251,7 @@ class Item(models.Model):
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
update_poster = False update_poster = False
update_ids = False
if not self.id: if not self.id:
if not self.itemId: if not self.itemId:
self.itemId = str(uuid.uuid1()) self.itemId = str(uuid.uuid1())
@ -278,6 +279,7 @@ class Item(models.Model):
q = Item.objects.filter(oxdbId=oxdbId).exclude(id=self.id) q = Item.objects.filter(oxdbId=oxdbId).exclude(id=self.id)
self.oxdbId = oxdbId self.oxdbId = oxdbId
update_poster = True update_poster = True
update_ids = True
#id changed, what about existing item with new id? #id changed, what about existing item with new id?
if settings.USE_IMDB and len(self.itemId) != 7 and self.oxdbId != self.itemId: if settings.USE_IMDB and len(self.itemId) != 7 and self.oxdbId != self.itemId:
@ -302,8 +304,15 @@ class Item(models.Model):
self.update_sort() self.update_sort()
self.json = self.get_json() self.json = self.get_json()
super(Item, self).save(*args, **kwargs) super(Item, self).save(*args, **kwargs)
if update_ids:
for c in self.clips.all(): c.save()
for a in self.annotations.all():
public_id = a.public_id.split('/')[1]
a.public_id = "%s/%s" % ( self.itemId, public_id)
a.save()
if update_poster: if update_poster:
return tasks.update_poster.delay(self.itemId) return tasks.update_poster.delay(self.itemId)
return None return None
def delete_files(self): def delete_files(self):