delete all derivatives removing a file

This commit is contained in:
j 2013-09-26 20:58:03 +00:00
parent 4b575c2c89
commit c50db67150

View file

@ -380,16 +380,26 @@ class File(models.Model):
def all_paths(self): def all_paths(self):
return [self.path] + [i.path for i in self.instances.all()] return [self.path] + [i.path for i in self.instances.all()]
def delete(self, *args, **kwargs):
self.delete_files()
super(File, self).delete(*args, **kwargs)
def delete_frames(self): def delete_frames(self):
frames = os.path.join(settings.MEDIA_ROOT, self.get_path('frames')) frames = os.path.join(settings.MEDIA_ROOT, self.get_path('frames'))
if os.path.exists(frames): if os.path.exists(frames):
shutil.rmtree(frames) shutil.rmtree(frames)
def delete_files(self):
if self.data:
self.data.delete()
self.streams.all().delete()
prefix = os.path.join(settings.MEDIA_ROOT, self.get_path(''))
if os.path.exists(prefix):
shutil.rmtree(prefix)
def delete_file(sender, **kwargs): def delete_file(sender, **kwargs):
f = kwargs['instance'] f = kwargs['instance']
#FIXME: delete streams here f.delete_files()
if f.data:
f.data.delete()
pre_delete.connect(delete_file, sender=File) pre_delete.connect(delete_file, sender=File)
class Volume(models.Model): class Volume(models.Model):