def upload_file(self, filedata): filename = STORAGE.get_valid_name(filedata.name) filepath = os.path.join(self.path, filename) signals.filemanager_pre_upload.send(sender=self.__class__, filename=filename, path=self.path, filepath=filepath) STORAGE.save(filepath, filedata) signals.filemanager_post_upload.send(sender=self.__class__, filename=filename, path=self.path, filepath=filepath) return filename
def create_directory(self, name): name = STORAGE.get_valid_name(name) tmpfile = os.path.join(name, '.tmp') path = os.path.join(self.path, tmpfile) STORAGE.save(path, ContentFile('')) STORAGE.delete(path)
def rename(self, nameold, name): nameold, ext = os.path.splitext(nameold) nameold = nameold + ext name = slugify(re.sub('\d+', '', STORAGE.get_valid_name(name))) + ext oldpath = os.path.join(self.location, nameold) newpath = os.path.join(self.location, name) if os.path.exists(newpath): return False else: os.rename(oldpath, newpath) return name return False
def upload_file(self, filedata): filename = STORAGE.get_valid_name(filedata.name) filename, ext = os.path.splitext(filename) filename = slugify(re.sub("\d+", "", filename)) + ext filepath = os.path.join(self.path, filename) signals.filemanager_pre_upload.send(sender=self.__class__, filename=filename, path=self.path, filepath=filepath) STORAGE.save(filepath, filedata) signals.filemanager_post_upload.send(sender=self.__class__, filename=filename, path=self.path, filepath=filepath) return filename