diff --git a/pandora/document/models.py b/pandora/document/models.py index a4216b2f..601ee5f6 100644 --- a/pandora/document/models.py +++ b/pandora/document/models.py @@ -202,6 +202,7 @@ class Document(models.Model): self.get_ratio() self.oshash = ox.oshash(self.file.path) self.save() + self.delete_cache() return True, self.file.size return save_chunk(self, self.file, chunk, offset, name, done_cb) @@ -301,13 +302,17 @@ class Document(models.Model): Document.objects.filter(id=self.id).update(matches=matches) self.matches = matches + def delete_cache(self): + if self.file: + folder = os.path.dirname(self.file.path) + for f in glob('%s/*' % folder): + if f != self.file.path: + os.unlink(f) + def delete_document(sender, **kwargs): t = kwargs['instance'] if t.file: - folder = os.path.dirname(t.file.path) - for f in glob('%s/*' % folder): - if f != t.file.path: - os.unlink(f) + t.delete_cache() t.file.delete(save=False) pre_delete.connect(delete_document, sender=Document) diff --git a/pandora/document/views.py b/pandora/document/views.py index ec12cd4a..f4820438 100644 --- a/pandora/document/views.py +++ b/pandora/document/views.py @@ -353,10 +353,7 @@ def upload(request): else: #replace existing file if file.file: - folder = os.path.dirname(file.file.path) - for f in glob('%s/*' % folder): - if f != file.file.path: - os.unlink(f) + file.delete_cache() file.file.delete() file.uploading = True name, extension = request.POST['filename'].rsplit('.', 1)