def post(self, label='', content='', parent_id=None): """ Creates a new thread. Actually, on POST, the content will be included in a user comment instead of being the thread description :param label: :param content: :return: """ # TODO - SECURE THIS workspace = tmpl_context.workspace api = ContentApi(tmpl_context.current_user) with DBSession.no_autoflush: thread = api.create(ContentType.Thread, workspace, tmpl_context.folder, label) if not self._path_validation.validate_new_content(thread): DBSession.rollback() return render_invalid_integrity_chosen_path( thread.get_label(), ) # FIXME - DO NOT DUPLICATE FIRST MESSAGE # thread.description = content api.save(thread, ActionDescription.CREATION, do_notify=False) comment = api.create(ContentType.Comment, workspace, thread, label) comment.label = '' comment.description = content api.save(comment, ActionDescription.COMMENT, do_notify=False) api.do_notify(thread) tg.flash(_('Thread created'), CST.STATUS_OK) tg.redirect( self._std_url.format(tmpl_context.workspace_id, tmpl_context.folder_id, thread.content_id))
def post(self, label='', content=''): workspace = tmpl_context.workspace api = ContentApi(tmpl_context.current_user) with DBSession.no_autoflush: page = api.create(ContentType.Page, workspace, tmpl_context.folder, label) page.description = content if not self._path_validation.validate_new_content(page): DBSession.rollback() return render_invalid_integrity_chosen_path(page.get_label(), ) api.save(page, ActionDescription.CREATION, do_notify=True) tg.flash(_('Page created'), CST.STATUS_OK) redirect = '/workspaces/{}/folders/{}/pages/{}' tg.redirect( tg.url(redirect).format(tmpl_context.workspace_id, tmpl_context.folder_id, page.content_id))
def post(self, label='', file_data=None): # TODO - SECURE THIS workspace = tmpl_context.workspace folder = tmpl_context.folder api = ContentApi(tmpl_context.current_user) with DBSession.no_autoflush: file = api.create(ContentType.File, workspace, folder, label) api.update_file_data(file, file_data.filename, file_data.type, file_data.file.read()) # Display error page to user if chosen label is in conflict if not self._path_validation.validate_new_content(file): DBSession.rollback() return render_invalid_integrity_chosen_path( file.get_label_as_file(), ) api.save(file, ActionDescription.CREATION) tg.flash(_('File created'), CST.STATUS_OK) redirect = '/workspaces/{}/folders/{}/files/{}' tg.redirect( tg.url(redirect).format(tmpl_context.workspace_id, tmpl_context.folder_id, file.content_id))
def post(self, label, parent_id=None, can_contain_folders=False, can_contain_threads=False, can_contain_files=False, can_contain_pages=False): # TODO - SECURE THIS workspace = tmpl_context.workspace api = ContentApi(tmpl_context.current_user) redirect_url_tmpl = '/workspaces/{}/folders/{}' redirect_url = '' try: parent = None if parent_id: parent = api.get_one(int(parent_id), ContentType.Folder, workspace) with DBSession.no_autoflush: folder = api.create(ContentType.Folder, workspace, parent, label) subcontent = dict( folder=True if can_contain_folders == 'on' else False, thread=True if can_contain_threads == 'on' else False, file=True if can_contain_files == 'on' else False, page=True if can_contain_pages == 'on' else False) api.set_allowed_content(folder, subcontent) if not self._path_validation.validate_new_content(folder): DBSession.rollback() return render_invalid_integrity_chosen_path( folder.get_label(), ) api.save(folder) tg.flash(_('Folder created'), CST.STATUS_OK) redirect_url = redirect_url_tmpl.format(tmpl_context.workspace_id, folder.content_id) except Exception as e: error_msg = 'An unexpected exception has been catched. ' \ 'Look at the traceback below.' logger.error(self, error_msg) traceback.print_exc() tb = sys.exc_info()[2] tg.flash( _('Folder not created: {}').format(e.with_traceback(tb)), CST.STATUS_ERROR) if parent_id: redirect_url = \ redirect_url_tmpl.format(tmpl_context.workspace_id, parent_id) else: redirect_url = \ '/workspaces/{}'.format(tmpl_context.workspace_id) #### # # INFO - D.A. - 2014-10-22 - Do not put redirect in a # try/except block as redirect is using exceptions! # tg.redirect(tg.url(redirect_url))