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


Python logic.NotFound方法代码示例

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


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

示例1: resource_update

# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import NotFound [as 别名]
def resource_update(context, data_dict):
    model = context['model']
    user = context.get('user')
    resource = logic_auth.get_resource_object(context, data_dict)

    # check authentication against package
    pkg = model.Package.get(resource.package_id)
    if not pkg:
        raise logic.NotFound(
            _('No package found for this resource, cannot check auth.')
        )

    pkg_dict = {'id': pkg.id}
    authorized = authz.is_authorized('package_update', context, pkg_dict).get('success')

    if not authorized:
        return {'success': False,
                'msg': _('User %s not authorized to edit resource %s') %
                        (str(user), resource.id)}
    else:
        return {'success': True} 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:23,代码来源:update.py

示例2: resource_delete

# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import NotFound [as 别名]
def resource_delete(context, data_dict):
    model = context['model']
    user = context.get('user')
    resource = get_resource_object(context, data_dict)

    # check authentication against package
    pkg = model.Package.get(resource.package_id)
    if not pkg:
        raise logic.NotFound(_('No package found for this resource, cannot check auth.'))

    pkg_dict = {'id': pkg.id}
    authorized = authz.is_authorized('package_delete', context, pkg_dict).get('success')

    if not authorized:
        return {'success': False, 'msg': _('User %s not authorized to delete resource %s') % (user, resource.id)}
    else:
        return {'success': True} 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:19,代码来源:delete.py

示例3: _get_object

# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import NotFound [as 别名]
def _get_object(context, data_dict, name, class_name):
    # return the named item if in the data_dict, or get it from
    # model.class_name
    try:
        return context[name]
    except KeyError:
        model = context['model']
        if not data_dict:
            data_dict = {}
        id = data_dict.get('id', None)
        if not id:
            raise logic.ValidationError('Missing id, can not get {0} object'
                                        .format(class_name))
        obj = getattr(model, class_name).get(id)
        if not obj:
            raise logic.NotFound
        # Save in case we need this again during the request
        context[name] = obj
        return obj 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:21,代码来源:__init__.py

示例4: package_revision_list

# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import NotFound [as 别名]
def package_revision_list(context, data_dict):
    '''Return a dataset (package)'s revisions as a list of dictionaries.

    :param id: the id or name of the dataset
    :type id: string

    '''
    model = context["model"]
    id = _get_or_bust(data_dict, "id")
    pkg = model.Package.get(id)
    if pkg is None:
        raise NotFound

    _check_access('package_revision_list', context, data_dict)

    revision_dicts = []
    for revision, object_revisions in pkg.all_related_revisions:
        revision_dicts.append(model.revision_as_dict(revision,
                                                     include_packages=False,
                                                     include_groups=False))
    return revision_dicts 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:23,代码来源:get.py

示例5: resource_view_show

# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import NotFound [as 别名]
def resource_view_show(context, data_dict):
    '''
    Return the metadata of a resource_view.

    :param id: the id of the resource_view
    :type id: string

    :rtype: dictionary
    '''
    model = context['model']
    id = _get_or_bust(data_dict, 'id')

    resource_view = model.ResourceView.get(id)
    if not resource_view:
        _check_access('resource_view_show', context, data_dict)
        raise NotFound

    context['resource_view'] = resource_view
    context['resource'] = model.Resource.get(resource_view.resource_id)

    _check_access('resource_view_show', context, data_dict)
    return model_dictize.resource_view_dictize(resource_view, context) 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:24,代码来源:get.py

示例6: resource_view_list

# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import NotFound [as 别名]
def resource_view_list(context, data_dict):
    '''
    Return the list of resource views for a particular resource.

    :param id: the id of the resource
    :type id: string

    :rtype: list of dictionaries.
    '''
    model = context['model']
    id = _get_or_bust(data_dict, 'id')
    resource = model.Resource.get(id)
    if not resource:
        raise NotFound
    context['resource'] = resource
    _check_access('resource_view_list', context, data_dict)
    q = model.Session.query(model.ResourceView).filter_by(resource_id=id)
    ## only show views when there is the correct plugin enabled
    resource_views = [
        resource_view for resource_view
        in q.order_by(model.ResourceView.order).all()
        if datapreview.get_view_plugin(resource_view.view_type)
    ]
    return model_dictize.resource_view_list_dictize(resource_views, context) 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:26,代码来源:get.py

示例7: revision_show

# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import NotFound [as 别名]
def revision_show(context, data_dict):
    '''Return the details of a revision.

    :param id: the id of the revision
    :type id: string

    :rtype: dictionary
    '''
    model = context['model']
    api = context.get('api_version')
    id = _get_or_bust(data_dict, 'id')
    ref_package_by = 'id' if api == 2 else 'name'

    rev = model.Session.query(model.Revision).get(id)
    if rev is None:
        raise NotFound
    rev_dict = model.revision_as_dict(rev, include_packages=True,
                                      ref_package_by=ref_package_by)
    return rev_dict 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:21,代码来源:get.py

示例8: vocabulary_show

# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import NotFound [as 别名]
def vocabulary_show(context, data_dict):
    '''Return a single tag vocabulary.

    :param id: the id or name of the vocabulary
    :type id: string
    :return: the vocabulary.
    :rtype: dictionary

    '''
    _check_access('vocabulary_show', context, data_dict)

    model = context['model']
    vocab_id = data_dict.get('id')
    if not vocab_id:
        raise ValidationError({'id': _('id not in data')})
    vocabulary = model.vocabulary.Vocabulary.get(vocab_id)
    if vocabulary is None:
        raise NotFound(_('Could not find vocabulary "%s"') % vocab_id)
    vocabulary_dict = model_dictize.vocabulary_dictize(vocabulary, context)
    return vocabulary_dict 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:22,代码来源:get.py

示例9: help_show

# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import NotFound [as 别名]
def help_show(context, data_dict):
    '''Return the help string for a particular API action.

    :param name: Action function name (eg `user_create`, `package_search`)
    :type name: string
    :returns: The help string for the action function, or None if the function
              does not have a docstring.
    :rtype: string

    :raises: :class:`ckan.logic.NotFound`: if the action function doesn't exist

    '''

    function_name = logic.get_or_bust(data_dict, 'name')

    _check_access('help_show', context, data_dict)

    try:
        function = logic.get_action(function_name)
    except KeyError:
        raise NotFound('Action function not found')

    return function.__doc__ 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:25,代码来源:get.py

示例10: get_domain_object

# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import NotFound [as 别名]
def get_domain_object(model, domain_object_ref):
    '''For an id or name, return the corresponding domain object.
    (First match returned, in order: system, package, group, auth_group, user).
    '''
    if domain_object_ref in ('system', 'System'):
        return model.System
    pkg = model.Package.get(domain_object_ref)
    if pkg:
        return pkg
    group = model.Group.get(domain_object_ref)
    if group:
        return group
    user = model.User.get(domain_object_ref)
    if user:
        return user
    raise NotFound('Domain object %r not found' % domain_object_ref) 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:18,代码来源:__init__.py

示例11: test_member_list

# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import NotFound [as 别名]
def test_member_list(self):
        self._member_create(self.pkgs[0].id, 'package', 'public')
        self._member_create(self.pkgs[1].id, 'package', 'public')
        res = self._member_list('package')
        assert (self.pkgs[0].id, 'package', 'public') in res
        assert (self.pkgs[1].id, 'package', 'public') in res

        res = self._member_list('user', 'admin')
        assert len(res) == 0, res

        assert_raises(logic.NotFound,
                      self._member_list, 'user', 'admin', 'inexistent_group')

        self._member_create(self.user.id, 'user', 'admin')
        res = self._member_list('user', 'admin')
        assert (self.user.id, 'user', 'Admin') in res, res 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:18,代码来源:test_member.py

示例12: read

# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import NotFound [as 别名]
def read(self, id):
        context = {'model': model, 'session': model.Session,
                   'user': c.user, 'auth_user_obj': c.userobj,
                   'for_view': True}

        data_dict = {'id': id}
        try:
            c.tag = logic.get_action('tag_show')(context, data_dict)
        except logic.NotFound:
            base.abort(404, _('Tag not found'))

        if asbool(config.get('ckan.legacy_templates', False)):
            return base.render('tag/read.html')
        else:
            h.redirect_to(controller='package', action='search',
                          tags=c.tag.get('name')) 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:18,代码来源:tag.py

示例13: read

# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import NotFound [as 别名]
def read(self, id, limit=20):
        group_type = self._ensure_controller_matches_group_type(
            id.split('@')[0])

        context = {'model': model, 'session': model.Session,
                   'user': c.user,
                   'schema': self._db_to_form_schema(group_type=group_type),
                   'for_view': True}
        data_dict = {'id': id, 'type': group_type}

        # unicode format (decoded from utf8)
        c.q = request.params.get('q', '')

        try:
            # Do not query for the group datasets when dictizing, as they will
            # be ignored and get requested on the controller anyway
            data_dict['include_datasets'] = False
            c.group_dict = self._action('group_show')(context, data_dict)
            c.group = context['group']
        except (NotFound, NotAuthorized):
            abort(404, _('Group not found'))

        self._read(id, limit, group_type)
        return render(self._read_template(c.group_dict['type']),
                      extra_vars={'group_type': group_type}) 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:27,代码来源:group.py

示例14: _save_new

# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import NotFound [as 别名]
def _save_new(self, context, group_type=None):
        try:
            data_dict = clean_dict(dict_fns.unflatten(
                tuplize_dict(parse_params(request.params))))
            data_dict['type'] = group_type or 'group'
            context['message'] = data_dict.get('log_message', '')
            data_dict['users'] = [{'name': c.user, 'capacity': 'admin'}]
            group = self._action('group_create')(context, data_dict)

            # Redirect to the appropriate _read route for the type of group
            h.redirect_to(group['type'] + '_read', id=group['name'])
        except (NotFound, NotAuthorized), e:
            abort(404, _('Group not found'))
        except dict_fns.DataError:
            abort(400, _(u'Integrity Error'))
        except ValidationError, e:
            errors = e.error_dict
            error_summary = e.error_summary
            return self.new(data_dict, errors, error_summary) 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:21,代码来源:group.py

示例15: _save_edit

# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import NotFound [as 别名]
def _save_edit(self, id, context):
        try:
            data_dict = clean_dict(dict_fns.unflatten(
                tuplize_dict(parse_params(request.params))))
            context['message'] = data_dict.get('log_message', '')
            data_dict['id'] = id
            context['allow_partial_update'] = True
            group = self._action('group_update')(context, data_dict)
            if id != group['name']:
                self._force_reindex(group)

            h.redirect_to('%s_read' % group['type'], id=group['name'])
        except (NotFound, NotAuthorized), e:
            abort(404, _('Group not found'))
        except dict_fns.DataError:
            abort(400, _(u'Integrity Error'))
        except ValidationError, e:
            errors = e.error_dict
            error_summary = e.error_summary
            return self.edit(id, data_dict, errors, error_summary) 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:22,代码来源:group.py


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