def page_update(context, data_dict): logic.check_access('page_update', context, data_dict) validation.page_name_validator(data_dict, context) try: session = context['session'] page = pages_model.Page.get_by_id(id=data_dict['id']) if page is None: raise NotFound populate_page(page, data_dict) groups = data_dict.get('groups') process_groups(context, page, groups) tags = data_dict.get('tags') process_tags(context, page, tags) session.add(page) session.commit() return dictize.page_dictize(page) except Exception as e: ex_msg = e.message if hasattr(e, 'message') else str(e) message = 'Something went wrong while processing the request: {}'.format( ex_msg) raise logic.ValidationError({'message': message}, error_summary=message)
def page_show(context, data_dict): ''' Fetch page from database :param id: the id or name of the page :type id: str :return: dictized page :rtype: dict ''' page = pages_model.Page.get_by_id(id=data_dict['id']) if page is None: raise NotFound page_dict = dictize.page_dictize(page) logic.check_access('page_show', context, page_dict) return page_dict
def page_create(context, data_dict): model = context['model'] logic.check_access('page_create', context, data_dict) validation.page_name_validator(data_dict, context) try: page = pages_model.Page(name=data_dict['name'], title=data_dict.get('title'), description=data_dict.get('description'), type=data_dict.get('type'), state=data_dict.get('state'), sections=data_dict.get('sections'), status=data_dict.get('status')) model.Session.add(page) for grp_id in data_dict.get('groups', []): # Dealing with the case where grp_id is actually the name of the group group_dict = logic.get_action('group_show')(context, { 'id': grp_id }) # We validate for id duplication, so this shouldn't be true during create. if pages_model.PageGroupAssociation.exists( page_id=page.id, group_id=group_dict.get('id')): raise toolkit.ValidationError( "Group already associated with page.", error_summary=u"The group, {0}, is already in the page". format(group_dict.get('id'))) # create the association pages_model.PageGroupAssociation.create( page=page, group_id=group_dict.get('id'), defer_commit=True) model.Session.commit() page_dict = dictize.page_dictize(page) return page_dict except Exception as e: ex_msg = e.message if hasattr(e, 'message') else str(e) message = 'Something went wrong while processing the request: {}'.format( ex_msg) raise logic.ValidationError({'message': message}, error_summary=message)
def page_delete(context, data_dict): ''' Delete a meta information entry :param id: the id or name of the page :type id: str :return: deleted dictized page :rtype: dict ''' logic.check_access('page_delete', context, data_dict) model = context['model'] page = pages_model.Page.get_by_id(id=data_dict['id']) if page is None: raise NotFound page.delete() model.repo.commit() return dictize.page_dictize(page)
def page_show(context, data_dict): ''' Fetch page from database :param id: the id or name of the page :type id: str :return: dictized page :rtype: dict ''' logic.check_access('page_show', context, data_dict) id = data_dict.get('id') if not id: raise logic.ValidationError({'id': _('Missing value')}) page = pages_model.Page.get_by_id(id=id) if page is None: raise NotFound page_dict = dictize.page_dictize(page) page_dict['tags'] = _process_tags(page, context) # logic.check_access('page_show', context, page_dict) return page_dict