當前位置: 首頁>>代碼示例>>Python>>正文


Python toolkit.ObjectNotFound方法代碼示例

本文整理匯總了Python中ckan.plugins.toolkit.ObjectNotFound方法的典型用法代碼示例。如果您正苦於以下問題:Python toolkit.ObjectNotFound方法的具體用法?Python toolkit.ObjectNotFound怎麽用?Python toolkit.ObjectNotFound使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ckan.plugins.toolkit的用法示例。


在下文中一共展示了toolkit.ObjectNotFound方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: create_country_codes

# 需要導入模塊: from ckan.plugins import toolkit [as 別名]
# 或者: from ckan.plugins.toolkit import ObjectNotFound [as 別名]
def create_country_codes():
    '''Create country_codes vocab and tags, if they don't exist already.

    Note that you could also create the vocab and tags using CKAN's API,
    and once they are created you can edit them (e.g. to add and remove
    possible dataset country code values) using the API.

    '''
    user = tk.get_action('get_site_user')({'ignore_auth': True}, {})
    context = {'user': user['name']}
    try:
        data = {'id': 'country_codes'}
        tk.get_action('vocabulary_show')(context, data)
        logging.info("Example genre vocabulary already exists, skipping.")
    except tk.ObjectNotFound:
        logging.info("Creating vocab 'country_codes'")
        data = {'name': 'country_codes'}
        vocab = tk.get_action('vocabulary_create')(context, data)
        for tag in (u'uk', u'ie', u'de', u'fr', u'es'):
            logging.info(
                    "Adding tag {0} to vocab 'country_codes'".format(tag))
            data = {'name': tag, 'vocabulary_id': vocab['id']}
            tk.get_action('tag_create')(context, data) 
開發者ID:italia,項目名稱:daf-recipes,代碼行數:25,代碼來源:plugin.py

示例2: harvest_source_update

# 需要導入模塊: from ckan.plugins import toolkit [as 別名]
# 或者: from ckan.plugins.toolkit import ObjectNotFound [as 別名]
def harvest_source_update(context, data_dict):
    '''
        Authorization check for harvest source update

        It forwards the checks to package_update, which will check for
        organization membership, whether if sysadmin, etc according to the
        instance configuration.
    '''
    model = context.get('model')
    user = context.get('user')
    source_id = data_dict['id']

    pkg = model.Package.get(source_id)
    if not pkg:
        raise pt.ObjectNotFound(pt._('Harvest source not found'))

    context['package'] = pkg

    try:
        pt.check_access('package_update', context, data_dict)
        return {'success': True}
    except pt.NotAuthorized:
        return {'success': False,
                'msg': pt._('User {0} not authorized to update harvest source {1}').format(user, source_id)} 
開發者ID:italia,項目名稱:daf-recipes,代碼行數:26,代碼來源:update.py

示例3: harvest_source_delete

# 需要導入模塊: from ckan.plugins import toolkit [as 別名]
# 或者: from ckan.plugins.toolkit import ObjectNotFound [as 別名]
def harvest_source_delete(context, data_dict):
    '''
        Authorization check for harvest source deletion

        It forwards the checks to package_delete, which will check for
        organization membership, whether if sysadmin, etc according to the
        instance configuration.
    '''
    model = context.get('model')
    user = context.get('user')
    source_id = data_dict['id']

    pkg = model.Package.get(source_id)
    if not pkg:
        raise pt.ObjectNotFound(pt._('Harvest source not found'))

    context['package'] = pkg

    try:
        pt.check_access('package_delete', context, data_dict)
        return {'success': True}
    except pt.NotAuthorized:
        return {'success': False,
                'msg': pt._('User {0} not authorized to delete harvest source {1}').format(user, source_id)} 
開發者ID:italia,項目名稱:daf-recipes,代碼行數:26,代碼來源:delete.py

示例4: harvest_job_create

# 需要導入模塊: from ckan.plugins import toolkit [as 別名]
# 或者: from ckan.plugins.toolkit import ObjectNotFound [as 別名]
def harvest_job_create(context, data_dict):
    '''
        Authorization check for harvest job creation

        It forwards the checks to package_update, ie the user can only create
        new jobs if she is allowed to edit the harvest source dataset.
    '''
    model = context['model']
    source_id = data_dict['source_id']

    pkg = model.Package.get(source_id)
    if not pkg:
        raise pt.ObjectNotFound(pt._('Harvest source not found'))

    context['package'] = pkg
    try:
        pt.check_access('package_update', context, data_dict)
        return {'success': True}
    except pt.NotAuthorized:
        return {'success': False,
                'msg': pt._('User not authorized to create a job for source {0}').format(source_id)} 
開發者ID:italia,項目名稱:daf-recipes,代碼行數:23,代碼來源:create.py

示例5: test_remote_groups_only_local

# 需要導入模塊: from ckan.plugins import toolkit [as 別名]
# 或者: from ckan.plugins.toolkit import ObjectNotFound [as 別名]
def test_remote_groups_only_local(self):
        # Create an existing group
        Group(id='group1-id', name='group1')

        config = {'remote_groups': 'only_local'}
        results_by_guid = run_harvest(
            url='http://localhost:%s' % mock_ckan.PORT,
            harvester=CKANHarvester(),
            config=json.dumps(config))
        assert 'dataset1-id' in results_by_guid

        # Check that the dataset was added to the existing local group
        dataset = call_action('package_show', {}, id=mock_ckan.DATASETS[0]['id'])
        assert_equal(dataset['groups'][0]['id'], mock_ckan.DATASETS[0]['groups'][0]['id'])

        # Check that the other remote group was not created locally
        assert_raises(toolkit.ObjectNotFound, call_action, 'group_show', {},
                      id='remote-group') 
開發者ID:italia,項目名稱:daf-recipes,代碼行數:20,代碼來源:test_ckanharvester.py

示例6: _create

# 需要導入模塊: from ckan.plugins import toolkit [as 別名]
# 或者: from ckan.plugins.toolkit import ObjectNotFound [as 別名]
def _create(cls, target_class, *args, **kwargs):
        if args:
            assert False, "Positional args aren't supported, use keyword args."
        context = {'user': _get_action_user_name(kwargs)}
        # If there is an existing source for this URL, and we can't create
        # another source with that URL, just return the original one.
        try:
            source_dict = toolkit.get_action('harvest_source_show')(
                context, dict(url=kwargs['url']))
        except toolkit.ObjectNotFound:
            source_dict = toolkit.get_action('harvest_source_create')(
                context, kwargs)
        if cls._return_type == 'dict':
            return source_dict
        else:
            return cls.FACTORY_FOR.get(source_dict['id']) 
開發者ID:italia,項目名稱:daf-recipes,代碼行數:18,代碼來源:factories.py

示例7: get_vocabulary_items

# 需要導入模塊: from ckan.plugins import toolkit [as 別名]
# 或者: from ckan.plugins.toolkit import ObjectNotFound [as 別名]
def get_vocabulary_items(vocabulary_name, keys=None):
    try:
        tag_list = toolkit.get_action('tag_list')
        items = tag_list(data_dict={'vocabulary_id': vocabulary_name})

        tag_list = []
        for item in items:
            if keys:
                for key in keys:
                    if key == item:
                        localized_tag_name = interfaces.get_localized_tag_name(item)
                        tag_list.append(localized_tag_name)
            else:
                localized_tag_name = interfaces.get_localized_tag_name(item)
                tag_list.append({'text': localized_tag_name, 'value': item})

        return tag_list
    except toolkit.ObjectNotFound:
        return [] 
開發者ID:italia,項目名稱:daf-recipes,代碼行數:21,代碼來源:helpers.py

示例8: showcase_delete

# 需要導入模塊: from ckan.plugins import toolkit [as 別名]
# 或者: from ckan.plugins.toolkit import ObjectNotFound [as 別名]
def showcase_delete(context, data_dict):
    '''Delete a showcase. Showcase delete cascades to
    ShowcasePackageAssociation objects.

    :param id: the id or name of the showcase to delete
    :type id: string
    '''

    model = context['model']
    id = toolkit.get_or_bust(data_dict, 'id')

    entity = model.Package.get(id)

    if entity is None:
        raise toolkit.ObjectNotFound

    toolkit.check_access('ckanext_showcase_delete', context, data_dict)

    entity.purge()
    model.repo.commit() 
開發者ID:ckan,項目名稱:ckanext-showcase,代碼行數:22,代碼來源:delete.py

示例9: test_association_delete_attempt_with_non_existent_association

# 需要導入模塊: from ckan.plugins import toolkit [as 別名]
# 或者: from ckan.plugins.toolkit import ObjectNotFound [as 別名]
def test_association_delete_attempt_with_non_existent_association(self):
        '''
        Attempting to delete a non-existent association (package ids exist,
        but aren't associated with each other), will cause a NotFound error.
        '''
        sysadmin = factories.User(sysadmin=True)
        package_id = factories.Dataset()['id']
        showcase_id = factories.Dataset(type='showcase')['id']

        # No existing associations
        nosetools.assert_equal(model.Session.query(ShowcasePackageAssociation).count(), 0)

        context = {'user': sysadmin['name']}
        nosetools.assert_raises(toolkit.ObjectNotFound, helpers.call_action,
                                'ckanext_showcase_package_association_delete',
                                context=context, package_id=package_id,
                                showcase_id=showcase_id) 
開發者ID:ckan,項目名稱:ckanext-showcase,代碼行數:19,代碼來源:test_delete.py

示例10: setup_org

# 需要導入模塊: from ckan.plugins import toolkit [as 別名]
# 或者: from ckan.plugins.toolkit import ObjectNotFound [as 別名]
def setup_org(self):
        # get the organisation all users will be added to
        organization_id = toolkit.config[u'ckanext.ldap.organization.id']

        # set up context
        user = toolkit.get_action(u'get_site_user')({
            u'ignore_auth': True
        }, {})
        context = {
            u'user': user[u'name']
        }

        try:
            toolkit.get_action(u'organization_show')(context, {
                u'id': organization_id
            })
        except toolkit.ObjectNotFound:
            # see the following commit to understand why this line is here
            # http://github.com/ckan/ckanext-harvest/commit/f315f41c86cbde4a49ef869b6993598f8cb11e2d
            context.pop(u'__auth_audit', None)
            toolkit.get_action(u'organization_create')(context, {
                u'id': organization_id,
                u'name': organization_id
            }) 
開發者ID:NaturalHistoryMuseum,項目名稱:ckanext-ldap,代碼行數:26,代碼來源:ldap.py

示例11: group_create

# 需要導入模塊: from ckan.plugins import toolkit [as 別名]
# 或者: from ckan.plugins.toolkit import ObjectNotFound [as 別名]
def group_create(context, data_dict=None):
    # Get the user name of the logged-in user.
    user_name = context['user']

    # Get a list of the members of the 'curators' group.
    try:
        members = toolkit.get_action('member_list')(
            data_dict={'id': 'curators', 'object_type': 'user'})
    except toolkit.ObjectNotFound:
        # The curators group doesn't exist.
        return {'success': False,
                'msg': "The curators groups doesn't exist, so only sysadmins "
                       "are authorized to create groups."}

    # 'members' is a list of (user_id, object_type, capacity) tuples, we're
    # only interested in the user_ids.
    member_ids = [member_tuple[0] for member_tuple in members]

    # We have the logged-in user's user name, get their user id.
    convert_user_name_or_id_to_id = toolkit.get_converter(
        'convert_user_name_or_id_to_id')
    try:
        user_id = convert_user_name_or_id_to_id(user_name, context)
    except toolkit.Invalid:
        # The user doesn't exist (e.g. they're not logged-in).
        return {'success': False,
                'msg': 'You must be logged-in as a member of the curators '
                       'group to create new groups.'}

    # Finally, we can test whether the user is a member of the curators group.
    if user_id in member_ids:
        return {'success': True}
    else:
        return {'success': False,
                'msg': 'Only curators are allowed to create groups'} 
開發者ID:italia,項目名稱:daf-recipes,代碼行數:37,代碼來源:plugin_v4.py

示例12: datapusher_status

# 需要導入模塊: from ckan.plugins import toolkit [as 別名]
# 或者: from ckan.plugins.toolkit import ObjectNotFound [as 別名]
def datapusher_status(resource_id):
    try:
        return toolkit.get_action('datapusher_status')(
            {}, {'resource_id': resource_id})
    except toolkit.ObjectNotFound:
        return {
            'status': 'unknown'
        } 
開發者ID:italia,項目名稱:daf-recipes,代碼行數:10,代碼來源:helpers.py

示例13: create_country_codes

# 需要導入模塊: from ckan.plugins import toolkit [as 別名]
# 或者: from ckan.plugins.toolkit import ObjectNotFound [as 別名]
def create_country_codes():
    user = tk.get_action('get_site_user')({'ignore_auth': True}, {})
    context = {'user': user['name']}
    try:
        data = {'id': 'country_codes'}
        tk.get_action('vocabulary_show')(context, data)
    except tk.ObjectNotFound:
        data = {'name': 'country_codes'}
        vocab = tk.get_action('vocabulary_create')(context, data)
        for tag in (u'uk', u'ie', u'de', u'fr', u'es'):
            data = {'name': tag, 'vocabulary_id': vocab['id']}
            tk.get_action('tag_create')(context, data) 
開發者ID:italia,項目名稱:daf-recipes,代碼行數:14,代碼來源:plugin_v4.py

示例14: country_codes

# 需要導入模塊: from ckan.plugins import toolkit [as 別名]
# 或者: from ckan.plugins.toolkit import ObjectNotFound [as 別名]
def country_codes():
    create_country_codes()
    try:
        tag_list = tk.get_action('tag_list')
        country_codes = tag_list(data_dict={'vocabulary_id': 'country_codes'})
        return country_codes
    except tk.ObjectNotFound:
        return None 
開發者ID:italia,項目名稱:daf-recipes,代碼行數:10,代碼來源:plugin_v4.py

示例15: user_is_sysadmin

# 需要導入模塊: from ckan.plugins import toolkit [as 別名]
# 或者: from ckan.plugins.toolkit import ObjectNotFound [as 別名]
def user_is_sysadmin(context):
    '''
        Checks if the user defined in the context is a sysadmin

        rtype: boolean
    '''
    model = context['model']
    user = context['user']
    user_obj = model.User.get(user)
    if not user_obj:
        raise pt.Objectpt.ObjectNotFound('User {0} not found').format(user)

    return user_obj.sysadmin 
開發者ID:italia,項目名稱:daf-recipes,代碼行數:15,代碼來源:__init__.py


注:本文中的ckan.plugins.toolkit.ObjectNotFound方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。