def save_attachment(self, page_id, file_name, stream): file_id = str(uuid.uuid4()) page_path = os.path.join(self.__path, str(page_id)) file_path = os.path.join(page_path, file_id) Path(page_path).mkdir(parents=True, exist_ok=True) with open(file_path, 'wb') as fp: shutil.copyfileobj(stream, fp) storage_service = registry_service.main_service() storage_service.register_attachment(page_id, file_name, file_id)
def delete_attachment(self, page_id, file_name): storage_service = registry_service.main_service() storage_service.delete_attachment(page_id, file_name)
def list_attachments(self, page_id) -> List[str]: storage_service = registry_service.main_service() uploads = storage_service.get_page_attachments(page_id) file_names = [u.file_name for u in uploads] return file_names
def get_attachment_path(self, page_id, file_name) -> str: storage_service = registry_service.main_service() file_id = storage_service.get_attachment_file_id(page_id, file_name) file_path = os.path.join(self.__path, str(page_id), file_id) return file_path
def index(): pages = main_service().get_pages() return flask.render_template('index/index.html', notes=pages)