當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。