remove files

This commit is contained in:
j 2011-05-25 21:11:08 +02:00
parent 83cfa0c773
commit 1e985ebf63

View file

@ -241,9 +241,12 @@ class Item(models.Model):
tasks.update_poster.delay(self.itemId) tasks.update_poster.delay(self.itemId)
def delete_files(self): def delete_files(self):
shutil.rmtree(self.path('')) path = os.path.join(settings.MEDIA_ROOT, self.path())
if os.path.exists(path):
shutil.rmtree(path)
def delete(self, *args, **kwargs): def delete(self, *args, **kwargs):
self.streams.all().delete()
self.delete_files() self.delete_files()
super(Item, self).delete(*args, **kwargs) super(Item, self).delete(*args, **kwargs)
@ -251,15 +254,10 @@ class Item(models.Model):
''' '''
move all related tables to other and delete self move all related tables to other and delete self
''' '''
#FIXME: stream path is wrong after this, should this be dealt with in save?
# its more that streams have to be generated again after merging
for stream in self.streams.all():
stream.item = other
stream.save()
for l in self.lists.all(): for l in self.lists.all():
l.items.remove(self) l.remove(self)
if l.items.filter(id=other.id) == 0: if l.items.filter(id=other.id) == 0:
l.items.add(other) l.add(other)
#FIXME: should this really happen for annotations? #FIXME: should this really happen for annotations?
for a in self.annotations.all(): for a in self.annotations.all():
a.item = other a.item = other
@ -270,6 +268,7 @@ class Item(models.Model):
f.save() f.save()
self.delete() self.delete()
other.save() other.save()
#FIXME: update poster, stills and streams after this
def get_poster(self): def get_poster(self):
poster = {} poster = {}