From c50db67150b973d53e0858a3c38879a684d387d3 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Thu, 26 Sep 2013 20:58:03 +0000 Subject: [PATCH] delete all derivatives removing a file --- pandora/archive/models.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/pandora/archive/models.py b/pandora/archive/models.py index 4e80cb5e..f37c748f 100644 --- a/pandora/archive/models.py +++ b/pandora/archive/models.py @@ -379,17 +379,27 @@ class File(models.Model): def all_paths(self): 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): frames = os.path.join(settings.MEDIA_ROOT, self.get_path('frames')) if os.path.exists(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): f = kwargs['instance'] - #FIXME: delete streams here - if f.data: - f.data.delete() + f.delete_files() pre_delete.connect(delete_file, sender=File) class Volume(models.Model):