当前位置: 首页>>代码示例>>Python>>正文


Python helpers.flash_error方法代码示例

本文整理汇总了Python中ckan.lib.helpers.flash_error方法的典型用法代码示例。如果您正苦于以下问题:Python helpers.flash_error方法的具体用法?Python helpers.flash_error怎么用?Python helpers.flash_error使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ckan.lib.helpers的用法示例。


在下文中一共展示了helpers.flash_error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _action

# 需要导入模块: from ckan.lib import helpers [as 别名]
# 或者: from ckan.lib.helpers import flash_error [as 别名]
def _action(self, action, context, username, groupname, 
                dataset_type, classification, success_msg):
        try:
            toolkit.get_action(action)(context,
                            data_dict={'username': username, 
                                       'groupname': groupname, 
                                       'dataset_type': dataset_type,
                                       'classification': classification}
            )
        except toolkit.NotAuthorized:
            toolkit.abort(401,
                          toolkit._('Unauthorized to perform that action'))
        except toolkit.ObjectNotFound as e :
            error_message = (e.message or e.error_summary
                         or e.error_dict)
            helpers.flash_error(error_message)
        except toolkit.ValidationError as e:
            error_message = e.error_dict
            helpers.flash_error(error_message['message'])
        else:
            helpers.flash_success(toolkit._(success_msg)) 
开发者ID:abgov,项目名称:ckanext-classification,代码行数:23,代码来源:security_controller.py

示例2: abort

# 需要导入模块: from ckan.lib import helpers [as 别名]
# 或者: from ckan.lib.helpers import flash_error [as 别名]
def abort(status_code=None, detail='', headers=None, comment=None):
    '''Abort the current request immediately by returning an HTTP exception.

    This is a wrapper for :py:func:`pylons.controllers.util.abort` that adds
    some CKAN custom behavior, including allowing
    :py:class:`~ckan.plugins.interfaces.IAuthenticator` plugins to alter the
    abort response, and showing flash messages in the web interface.

    '''
    if status_code == 403:
        # Allow IAuthenticator plugins to alter the abort
        for item in p.PluginImplementations(p.IAuthenticator):
            result = item.abort(status_code, detail, headers, comment)
            (status_code, detail, headers, comment) = result

    if detail and status_code != 503:
        h.flash_error(detail)
    # #1267 Convert detail to plain text, since WebOb 0.9.7.1 (which comes
    # with Lucid) causes an exception when unicode is received.
    detail = detail.encode('utf8')
    return _abort(status_code=status_code,
                  detail=detail,
                  headers=headers,
                  comment=comment) 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:26,代码来源:base.py

示例3: follow

# 需要导入模块: from ckan.lib import helpers [as 别名]
# 或者: from ckan.lib.helpers import flash_error [as 别名]
def follow(self, id):
        '''Start following this group.'''
        self._ensure_controller_matches_group_type(id)
        context = {'model': model,
                   'session': model.Session,
                   'user': c.user}
        data_dict = {'id': id}
        try:
            get_action('follow_group')(context, data_dict)
            group_dict = get_action('group_show')(context, data_dict)
            h.flash_success(_("You are now following {0}").format(
                group_dict['title']))
        except ValidationError as e:
            error_message = (e.message or e.error_summary
                             or e.error_dict)
            h.flash_error(error_message)
        except NotAuthorized as e:
            h.flash_error(e.message)
        h.redirect_to(controller='group', action='read', id=id) 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:21,代码来源:group.py

示例4: unfollow

# 需要导入模块: from ckan.lib import helpers [as 别名]
# 或者: from ckan.lib.helpers import flash_error [as 别名]
def unfollow(self, id):
        '''Stop following this group.'''
        self._ensure_controller_matches_group_type(id)
        context = {'model': model,
                   'session': model.Session,
                   'user': c.user}
        data_dict = {'id': id}
        try:
            get_action('unfollow_group')(context, data_dict)
            group_dict = get_action('group_show')(context, data_dict)
            h.flash_success(_("You are no longer following {0}").format(
                group_dict['title']))
        except ValidationError as e:
            error_message = (e.message or e.error_summary
                             or e.error_dict)
            h.flash_error(error_message)
        except (NotFound, NotAuthorized) as e:
            error_message = e.message
            h.flash_error(error_message)
        h.redirect_to(controller='group', action='read', id=id) 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:22,代码来源:group.py

示例5: follow

# 需要导入模块: from ckan.lib import helpers [as 别名]
# 或者: from ckan.lib.helpers import flash_error [as 别名]
def follow(self, id):
        '''Start following this dataset.'''
        context = {'model': model,
                   'session': model.Session,
                   'user': c.user, 'auth_user_obj': c.userobj}
        data_dict = {'id': id}
        try:
            get_action('follow_dataset')(context, data_dict)
            package_dict = get_action('package_show')(context, data_dict)
            h.flash_success(_("You are now following {0}").format(
                package_dict['title']))
        except ValidationError as e:
            error_message = (e.message or e.error_summary
                             or e.error_dict)
            h.flash_error(error_message)
        except NotAuthorized as e:
            h.flash_error(e.message)
        h.redirect_to(controller='package', action='read', id=id) 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:20,代码来源:package.py

示例6: login

# 需要导入模块: from ckan.lib import helpers [as 别名]
# 或者: from ckan.lib.helpers import flash_error [as 别名]
def login(self, error=None):
        # Do any plugin login stuff
        for item in p.PluginImplementations(p.IAuthenticator):
            item.login()

        if 'error' in request.params:
            h.flash_error(request.params['error'])

        if not c.user:
            came_from = request.params.get('came_from')
            if not came_from:
                came_from = h.url_for(controller='user', action='logged_in',
                                      __ckan_no_root=True)
            c.login_handler = h.url_for(
                self._get_repoze_handler('login_handler_path'),
                came_from=came_from)
            if error:
                vars = {'error_summary': {'': error}}
            else:
                vars = {}
            return render('user/login.html', extra_vars=vars)
        else:
            return render('user/logout_first.html') 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:25,代码来源:user.py

示例7: logged_in

# 需要导入模块: from ckan.lib import helpers [as 别名]
# 或者: from ckan.lib.helpers import flash_error [as 别名]
def logged_in(self):
        # redirect if needed
        came_from = request.params.get('came_from', '')
        if h.url_is_local(came_from):
            return h.redirect_to(str(came_from))

        if c.user:
            context = None
            data_dict = {'id': c.user}

            user_dict = get_action('user_show')(context, data_dict)

            return self.me()
        else:
            err = _('Login failed. Bad username or password.')
            if asbool(config.get('ckan.legacy_templates', 'false')):
                h.flash_error(err)
                h.redirect_to(controller='user',
                              action='login', came_from=came_from)
            else:
                return self.login(error=err) 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:23,代码来源:user.py

示例8: unfollow

# 需要导入模块: from ckan.lib import helpers [as 别名]
# 或者: from ckan.lib.helpers import flash_error [as 别名]
def unfollow(self, id):
        '''Stop following this user.'''
        context = {'model': model,
                   'session': model.Session,
                   'user': c.user,
                   'auth_user_obj': c.userobj}
        data_dict = {'id': id, 'include_num_followers': True}
        try:
            get_action('unfollow_user')(context, data_dict)
            user_dict = get_action('user_show')(context, data_dict)
            h.flash_success(_("You are no longer following {0}").format(
                user_dict['display_name']))
        except (NotFound, NotAuthorized) as e:
            error_message = e.message
            h.flash_error(error_message)
        except ValidationError as e:
            error_message = (e.error_summary or e.message
                             or e.error_dict)
            h.flash_error(error_message)
        h.redirect_to(controller='user', action='read', id=id) 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:22,代码来源:user.py

示例9: refresh

# 需要导入模块: from ckan.lib import helpers [as 别名]
# 或者: from ckan.lib.helpers import flash_error [as 别名]
def refresh(self, id):
        try:
            context = {'model':model, 'user':c.user, 'session':model.Session}
            p.toolkit.get_action('harvest_job_create')(
                context, {'source_id': id, 'run': True})
            h.flash_success(_('Harvest will start shortly. Refresh this page for updates.'))
        except p.toolkit.ObjectNotFound:
            abort(404,_('Harvest source not found'))
        except p.toolkit.NotAuthorized:
            abort(401,self.not_auth_message)
        except HarvestSourceInactiveError, e:
            h.flash_error(_('Cannot create new harvest jobs on inactive '
                            'sources. First, please change the source status '
                            'to \'active\'.'))
        except HarvestJobExists, e:
            h.flash_notice(_('A harvest job has already been scheduled for '
                             'this source'))
        except Exception, e:
                msg = 'An error occurred: [%s]' % str(e)
                h.flash_error(msg)

        h.redirect_to(h.url_for('{0}_admin'.format(DATASET_TYPE_NAME), id=id)) 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:24,代码来源:view.py

示例10: manage

# 需要导入模块: from ckan.lib import helpers [as 别名]
# 或者: from ckan.lib.helpers import flash_error [as 别名]
def manage(self, id):
        context, controller = self._get_context_controller()
        username = toolkit.request.params.get('username')
        dataset_type = toolkit.request.params.get("field-dataset_type")
        classification = toolkit.request.params.get('field-classification')
        group_object = model.Group.get(id)
        groupname = group_object.name

        toolkit.c.group_dict = group_object

        if toolkit.request.method == 'POST':
            if username:
                user_object = model.User.get(username)
                if not user_object:
                    helpers.flash_error("User \"{0}\" not exist!".format(username))
                else:
                    self._action('security_member_create', 
                             context, 
                             username, 
                             groupname, 
                             dataset_type,
                             classification,
                             "User \"{0}\" is now a member of resource classification on type \"{1}\"".format(username, dataset_type))
            else:
                helpers.flash_error("Please input username first.")
            return toolkit.redirect_to(toolkit.url_for(controller=controller,
                                                       action='manage', 
                                                       id=id))

        security_members_list = toolkit.get_action('security_member_list')(context, 
                                                    data_dict={'groupname': groupname})
        return toolkit.render(
            'organization/manage_security_members.html',
            extra_vars={
                'security_members_list': security_members_list,
            }
        ) 
开发者ID:abgov,项目名称:ckanext-classification,代码行数:39,代码来源:security_controller.py

示例11: fail_if_private

# 需要导入模块: from ckan.lib import helpers [as 别名]
# 或者: from ckan.lib.helpers import flash_error [as 别名]
def fail_if_private(self, dataset, dataset_url):
        if dataset['private']:
            h.flash_error("Cannot add a DOI to a private dataset")
            toolkit.redirect_to(dataset_url) 
开发者ID:Psykar,项目名称:ckanext-ands,代码行数:6,代码来源:controller.py

示例12: dataset_doi_admin_process

# 需要导入模块: from ckan.lib import helpers [as 别名]
# 或者: from ckan.lib.helpers import flash_error [as 别名]
def dataset_doi_admin_process(self, dataset_url, dataset):
        # If running on local machine, just resolve DOI to the dev server
        if 'localhost' in dataset_url or '127.0.0.1' in dataset_url:
            xml_url = config.get('ckanext.ands.debug_url')
        else:
            xml_url = dataset_url

        post_data = request.POST['xml']

        resp = post_doi_request(xml_url, post_data)
        try:
            json = loads(resp.content)
        except ValueError as exp:
            h.flash_error("Invalid response from DOI server: {} :: {}".format(exp, resp.content))
            return toolkit.redirect_to(dataset_url)
        try:
            response_dict = json["response"]
        except KeyError:
            h.flash_error("Response had no response key: {}".format(json))
            return toolkit.redirect_to(dataset_url)

        doi = response_dict["doi"]
        response_code = response_dict["responsecode"]
        success_code = "MT001"

        if response_code == success_code:
            dataset['doi_id'] = doi
            toolkit.get_action('package_update')(None, dataset)

            email_requestors(dataset['id'])

            h.flash_success("DOI Created successfully")
        else:
            type = response_dict["type"]
            err_msg = response_dict["message"]
            verbose_msg = response_dict["verbosemessage"]
            msg = response_code + ' - ' + type + '. ' + verbose_msg + '. ' + err_msg
            h.flash_error(_(msg))

        return toolkit.redirect_to(dataset_url) 
开发者ID:Psykar,项目名称:ckanext-ands,代码行数:42,代码来源:controller.py

示例13: _save_new

# 需要导入模块: from ckan.lib import helpers [as 别名]
# 或者: from ckan.lib.helpers import flash_error [as 别名]
def _save_new(self, context):
        try:
            data_dict = logic.clean_dict(unflatten(
                logic.tuplize_dict(logic.parse_params(request.params))))
            context['message'] = data_dict.get('log_message', '')
            captcha.check_recaptcha(request)
            user = get_action('user_create')(context, data_dict)
        except NotAuthorized:
            abort(403, _('Unauthorized to create user %s') % '')
        except NotFound, e:
            abort(404, _('User not found'))
        except DataError:
            abort(400, _(u'Integrity Error'))
        except captcha.CaptchaError:
            error_msg = _(u'Bad Captcha. Please try again.')
            h.flash_error(error_msg)
            return self.new(data_dict)
        except ValidationError, e:
            errors = e.error_dict
            error_summary = e.error_summary
            return self.new(data_dict, errors, error_summary)
        if not c.user:
            # log the user in programatically
            set_repoze_user(data_dict['name'])
            h.redirect_to(controller='user', action='me', __ckan_no_root=True)
        else:
            # #1799 User has managed to register whilst logged in - warn user
            # they are not re-logged in as new user.
            h.flash_success(_('User "%s" is now registered but you are still '
                            'logged in as "%s" from before') %
                            (data_dict['name'], c.user))
            if authz.is_sysadmin(c.user):
                # the sysadmin created a new user. We redirect him to the
                # activity page for the newly created user
                h.redirect_to(controller='user',
                              action='activity',
                              id=data_dict['name'])
            else:
                return render('user/logout_first.html') 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:41,代码来源:user.py

示例14: clear

# 需要导入模块: from ckan.lib import helpers [as 别名]
# 或者: from ckan.lib.helpers import flash_error [as 别名]
def clear(self, id):
        try:
            context = {'model':model, 'user':c.user, 'session':model.Session}
            p.toolkit.get_action('harvest_source_clear')(context,{'id':id})
            h.flash_success(_('Harvest source cleared'))
        except p.toolkit.ObjectNotFound:
            abort(404,_('Harvest source not found'))
        except p.toolkit.NotAuthorized:
            abort(401,self.not_auth_message)
        except Exception, e:
            msg = 'An error occurred: [%s]' % str(e)
            h.flash_error(msg)

        h.redirect_to(h.url_for('{0}_admin'.format(DATASET_TYPE_NAME), id=id)) 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:16,代码来源:view.py

示例15: clear

# 需要导入模块: from ckan.lib import helpers [as 别名]
# 或者: from ckan.lib.helpers import flash_error [as 别名]
def clear(self):
        '''
        Clears the PyCSW database
        '''
        config_path = config.get('ckan.ioos_theme.pycsw_config')
        if os.path.exists(config_path):
            try:
                self._clear_pycsw(config_path)
                h.flash_success(_('PyCSW has been cleared'))
            except Exception:
                h.flash_error('Unable to clear PyCSW, see logs for details')
        else:
            h.flash_error('Config for PyCSW doesn\'t exist')
        h.redirect_to(controller='ckanext.ioos_theme.controllers.csw:CswController', action='index')
        return 
开发者ID:ioos,项目名称:catalog-ckan,代码行数:17,代码来源:csw.py


注:本文中的ckan.lib.helpers.flash_error方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。