From fa473c4d1c443d87311c97486fb92d5971db6b54 Mon Sep 17 00:00:00 2001 From: Trupti Rajesh Kini Date: Wed, 11 Jan 2017 13:14:44 +0530 Subject: Fixed duplicate notebook bug On every upload the files were getting duplicated with different names instead of overwriting. eg: When chapter 12 is uploaded twice, django by default used to create 12_1. This is fixed and it will now overwrite 12 itself.--- tbc/models.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tbc') diff --git a/tbc/models.py b/tbc/models.py index 9b2adbf..48c6952 100644 --- a/tbc/models.py +++ b/tbc/models.py @@ -4,6 +4,8 @@ from PythonTBC import settings from django.contrib.admin.models import LogEntry from .local import sitemap_path from taggit.managers import TaggableManager +from django.core.files.storage import FileSystemStorage +import os CATEGORY = (("fluid mechanics", "Fluid Mechanics"), ("control systems", "Control Theory & Control Systems"), @@ -114,6 +116,14 @@ class Book(models.Model): name = self.title or 'Book' return '%s'%(name) +class OverwriteStorage(FileSystemStorage): + + def get_available_name(self, name): + if self.exists(name): + os.remove(os.path.join("/Site/tbc-python_fossee_in/PythonTBC/Python-TBC-Interface/tbc/static/Python-Textbook-Companions/", name)) + return name + +fs = OverwriteStorage(location="/Site/tbc-python_fossee_in/PythonTBC/Python-TBC-Interface/tbc/static/Python-Textbook-Companions/") class Chapters(models.Model): name = models.CharField(max_length=200) -- cgit