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 _helper(name, filetype): return { 'filepath': os.path.join(self.path, name), 'filetype': filetype, 'filename': name, 'filedate': STORAGE.modified_time(os.path.join(self.path, name)), 'filesize': sizeof_fmt(STORAGE.size(os.path.join(self.path, name))), }
def _helper(name, filetype): return { 'filepath': os.path.join(self.path, name), 'filetype': filetype, 'filename': name, 'filedate': STORAGE.get_modified_time(os.path.join(self.path, name)), 'filesize': sizeof_fmt(STORAGE.size(os.path.join(self.path, name))), 'fileurl' : os.path.join(settings.MEDIA_URL, self.abspath, name), }
def file_details(self): filename = self.path.rsplit('/', 1)[-1] return { 'directory': os.path.dirname(self.path), 'filepath': self.path, 'filename': filename, 'filesize': sizeof_fmt(STORAGE.size(self.location)), 'filedate': STORAGE.modified_time(self.location), 'fileurl': self.url, }
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
def directory_list(self): listing = [] directories, files = STORAGE.listdir(self.location) def _helper(name, filetype): return { 'filepath': os.path.join(self.path, name), 'filetype': filetype, 'filename': name, 'filedate': STORAGE.get_modified_time(os.path.join(self.path, name)), 'filesize': sizeof_fmt(STORAGE.size(os.path.join(self.path, name))), } for directoryname in directories: listing.append(_helper(directoryname, 'Directory')) for filename in files: listing.append(_helper(filename, 'File')) return listing
def _helper(name, filetype): perviewfull = '' perview = '' urlfolder = '' if filetype == 'Directory': filetype = '' urlfolder = '/' + name + '/' else: nm, ext = os.path.splitext(name) filetype = ext.replace('.', '') perviewfull = settings.BASE_URL + os.path.join(self.url, name) perview = settings.BASE_URL + os.path.join(self.url, name) return { 'urlfolder': urlfolder, 'isdir': os.path.isdir(os.path.join(self.location, name)), 'filetype': filetype, 'filename': name, 'lastmodified': int(os.path.getmtime(os.path.join(self.location, name))), 'perviewfull': perviewfull, 'perview': perview, 'size': STORAGE.size(os.path.join(self.path, name)), }
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 directory_list(self): listing = [] directories, files = STORAGE.listdir(self.location) def _helper(name, filetype): perviewfull = '' perview = '' urlfolder = '' if filetype == 'Directory': filetype = '' urlfolder = '/' + name + '/' else: nm, ext = os.path.splitext(name) filetype = ext.replace('.', '') perviewfull = settings.BASE_URL + os.path.join(self.url, name) perview = settings.BASE_URL + os.path.join(self.url, name) return { 'urlfolder': urlfolder, 'isdir': os.path.isdir(os.path.join(self.location, name)), 'filetype': filetype, 'filename': name, 'lastmodified': int(os.path.getmtime(os.path.join(self.location, name))), 'perviewfull': perviewfull, 'perview': perview, 'size': STORAGE.size(os.path.join(self.path, name)), } for directoryname in directories: listing.append(_helper(directoryname, 'Directory')) for filename in files: listing.append(_helper(filename, 'File')) return listing