cleanup document cache after upload

This commit is contained in:
j 2016-09-23 13:38:00 +02:00
parent 263b5c9ce2
commit b7659d6f14
2 changed files with 10 additions and 8 deletions

View File

@ -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)

View File

@ -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)