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


Python toolkit.get_action方法代码示例

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


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

示例1: group_create

# 需要导入模块: from ckan.plugins import toolkit [as 别名]
# 或者: from ckan.plugins.toolkit import get_action [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.
    members = toolkit.get_action('member_list')(
        data_dict={'id': 'curators', 'object_type': 'user'})

    # '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')
    user_id = convert_user_name_or_id_to_id(user_name, context)

    # 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,代码行数:26,代码来源:plugin_v3.py

示例2: harvest_sources_job_history_clear

# 需要导入模块: from ckan.plugins import toolkit [as 别名]
# 或者: from ckan.plugins.toolkit import get_action [as 别名]
def harvest_sources_job_history_clear(context, data_dict):
    '''
    Clears the history for all active harvest sources. All jobs and objects related to a harvest source will
    be cleared, but keeps the source itself.
    This is useful to clean history of long running harvest sources to start again fresh.
    The datasets imported from the harvest source will NOT be deleted!!!

    '''
    check_access('harvest_sources_clear', context, data_dict)

    job_history_clear_results = []
    # We assume that the maximum of 1000 (hard limit) rows should be enough
    result = logic.get_action('package_search')(context, {'fq': '+dataset_type:harvest', 'rows': 1000})
    harvest_packages = result['results']
    if harvest_packages:
        for data_dict in harvest_packages:
            try:
                clear_result = get_action('harvest_source_job_history_clear')(context, {'id': data_dict['id']})
                job_history_clear_results.append(clear_result)
            except NotFound:
                # Ignoring not existent harvest sources because of a possibly corrupt search index
                # Logging was already done in called function
                pass

    return job_history_clear_results 
开发者ID:italia,项目名称:daf-recipes,代码行数:27,代码来源:update.py

示例3: harvest_sources_reindex

# 需要导入模块: from ckan.plugins import toolkit [as 别名]
# 或者: from ckan.plugins.toolkit import get_action [as 别名]
def harvest_sources_reindex(context, data_dict):
    '''
        Reindexes all harvest source datasets with the latest status
    '''
    log.info('Reindexing all harvest sources')
    check_access('harvest_sources_reindex', context, data_dict)

    model = context['model']

    packages = model.Session.query(model.Package) \
                            .filter(model.Package.type == DATASET_TYPE_NAME) \
                            .filter(model.Package.state == u'active') \
                            .all()

    package_index = PackageSearchIndex()

    reindex_context = {'defer_commit': True}
    for package in packages:
        get_action('harvest_source_reindex')(
            reindex_context, {'id': package.id})

    package_index.commit()

    return True 
开发者ID:italia,项目名称:daf-recipes,代码行数:26,代码来源:update.py

示例4: harvest_source_reindex

# 需要导入模块: from ckan.plugins import toolkit [as 别名]
# 或者: from ckan.plugins.toolkit import get_action [as 别名]
def harvest_source_reindex(context, data_dict):
    '''Reindex a single harvest source'''

    harvest_source_id = logic.get_or_bust(data_dict, 'id')
    defer_commit = context.get('defer_commit', False)

    if 'extras_as_string'in context:
        del context['extras_as_string']
    context.update({'ignore_auth': True})
    package_dict = logic.get_action('harvest_source_show')(
        context, {'id': harvest_source_id})
    log.debug('Updating search index for harvest source: %s',
              package_dict.get('name') or harvest_source_id)

    # Remove configuration values
    new_dict = {}
    if package_dict.get('config'):
        config = json.loads(package_dict['config'])
        for key, value in package_dict.iteritems():
            if key not in config:
                new_dict[key] = value
    package_index = PackageSearchIndex()
    package_index.index_package(new_dict, defer_commit=defer_commit)

    return True 
开发者ID:italia,项目名称:daf-recipes,代码行数:27,代码来源:update.py

示例5: _create

# 需要导入模块: from ckan.plugins import toolkit [as 别名]
# 或者: from ckan.plugins.toolkit import get_action [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 'job_id' not in kwargs:
            kwargs['job_id'] = kwargs['job'].id
            kwargs['source_id'] = kwargs['job'].source.id
        # Remove 'job' to avoid it getting added as a HarvestObjectExtra
        if 'job' in kwargs:
            kwargs.pop('job')
        job_dict = toolkit.get_action('harvest_object_create')(
            context, kwargs)
        if cls._return_type == 'dict':
            return job_dict
        else:
            return cls.FACTORY_FOR.get(job_dict['id']) 
开发者ID:italia,项目名称:daf-recipes,代码行数:18,代码来源:factories.py

示例6: test_harvest_source_clear

# 需要导入模块: from ckan.plugins import toolkit [as 别名]
# 或者: from ckan.plugins.toolkit import get_action [as 别名]
def test_harvest_source_clear(self):
        source = factories.HarvestSourceObj(**SOURCE_DICT.copy())
        job = factories.HarvestJobObj(source=source)
        dataset = ckan_factories.Dataset()
        object_ = factories.HarvestObjectObj(job=job, source=source,
                                             package_id=dataset['id'])

        context = {'model': model, 'session': model.Session,
                   'ignore_auth': True, 'user': ''}
        result = toolkit.get_action('harvest_source_clear')(
            context, {'id': source.id})

        assert_equal(result, {'id': source.id})
        source = harvest_model.HarvestSource.get(source.id)
        assert source
        assert_equal(harvest_model.HarvestJob.get(job.id), None)
        assert_equal(harvest_model.HarvestObject.get(object_.id), None)
        assert_equal(model.Package.get(dataset['id']), None) 
开发者ID:italia,项目名称:daf-recipes,代码行数:20,代码来源:test_action.py

示例7: test_harvest_source_job_history_clear

# 需要导入模块: from ckan.plugins import toolkit [as 别名]
# 或者: from ckan.plugins.toolkit import get_action [as 别名]
def test_harvest_source_job_history_clear(self):
        # prepare
        source = factories.HarvestSourceObj(**SOURCE_DICT.copy())
        job = factories.HarvestJobObj(source=source)
        dataset = ckan_factories.Dataset()
        object_ = factories.HarvestObjectObj(job=job, source=source,
                                             package_id=dataset['id'])

        # execute
        context = {'model': model, 'session': model.Session,
                   'ignore_auth': True, 'user': ''}
        result = toolkit.get_action('harvest_source_job_history_clear')(
            context, {'id': source.id})

        # verify
        assert_equal(result, {'id': source.id})
        source = harvest_model.HarvestSource.get(source.id)
        assert source
        assert_equal(harvest_model.HarvestJob.get(job.id), None)
        assert_equal(harvest_model.HarvestObject.get(object_.id), None)
        dataset_from_db = model.Package.get(dataset['id'])
        assert dataset_from_db, 'is None'
        assert_equal(dataset_from_db.id, dataset['id']) 
开发者ID:italia,项目名称:daf-recipes,代码行数:25,代码来源:test_action.py

示例8: test_harvest_job_create_as_sysadmin

# 需要导入模块: from ckan.plugins import toolkit [as 别名]
# 或者: from ckan.plugins.toolkit import get_action [as 别名]
def test_harvest_job_create_as_sysadmin(self):
        source = factories.HarvestSource(**SOURCE_DICT.copy())

        site_user = toolkit.get_action('get_site_user')(
            {'model': model, 'ignore_auth': True}, {})['name']
        data_dict = {
            'source_id': source['id'],
            'run': True
            }
        job = toolkit.get_action('harvest_job_create')(
            {'user': site_user}, data_dict)

        assert_equal(job['source_id'], source['id'])
        assert_equal(job['status'], 'Running')
        assert_equal(job['gather_started'], None)
        assert_in('stats', job.keys()) 
开发者ID:italia,项目名称:daf-recipes,代码行数:18,代码来源:test_action.py

示例9: test_harvest_job_create_as_admin

# 需要导入模块: from ckan.plugins import toolkit [as 别名]
# 或者: from ckan.plugins.toolkit import get_action [as 别名]
def test_harvest_job_create_as_admin(self):
        # as if an admin user presses 'refresh'
        user = ckan_factories.User()
        user['capacity'] = 'admin'
        org = ckan_factories.Organization(users=[user])
        source_dict = dict(SOURCE_DICT.items() +
                           [('publisher_id', org['id'])])
        source = factories.HarvestSource(**source_dict)

        data_dict = {
            'source_id': source['id'],
            'run': True
            }
        job = toolkit.get_action('harvest_job_create')(
            {'user': user['name']}, data_dict)

        assert_equal(job['source_id'], source['id'])
        assert_equal(job['status'], 'Running')
        assert_equal(job['gather_started'], None)
        assert_in('stats', job.keys()) 
开发者ID:italia,项目名称:daf-recipes,代码行数:22,代码来源:test_action.py

示例10: test_create

# 需要导入模块: from ckan.plugins import toolkit [as 别名]
# 或者: from ckan.plugins.toolkit import get_action [as 别名]
def test_create(self):
        job = factories.HarvestJobObj()

        context = {
            'model': model,
            'session': model.Session,
            'ignore_auth': True,
        }
        data_dict = {
            'guid': 'guid',
            'content': 'content',
            'job_id': job.id,
            'extras': {'a key': 'a value'},
        }
        harvest_object = toolkit.get_action('harvest_object_create')(
            context, data_dict)

        # fetch the object from database to check it was created
        created_object = harvest_model.HarvestObject.get(harvest_object['id'])
        assert created_object.guid == harvest_object['guid'] == data_dict['guid'] 
开发者ID:italia,项目名称:daf-recipes,代码行数:22,代码来源:test_action.py

示例11: _last_catalog_modification

# 需要导入模块: from ckan.plugins import toolkit [as 别名]
# 或者: from ckan.plugins.toolkit import get_action [as 别名]
def _last_catalog_modification(self):
        '''
        Returns the date and time the catalog was last modified

        To be more precise, the most recent value for `metadata_modified` on a
        dataset.

        Returns a dateTime string in ISO format, or None if it could not be
        found.
        '''
        context = {
            'user': toolkit.get_action('get_site_user')(
                {'ignore_auth': True})['name']
        }
        result = toolkit.get_action('package_search')(context, {
            'sort': 'metadata_modified desc',
            'rows': 1,
        })
        if result and result.get('results'):
            return result['results'][0]['metadata_modified']
        return None

    # Public methods for profiles to implement 
开发者ID:italia,项目名称:daf-recipes,代码行数:25,代码来源:profiles.py

示例12: get_vocabulary_items

# 需要导入模块: from ckan.plugins import toolkit [as 别名]
# 或者: from ckan.plugins.toolkit import get_action [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

示例13: validate_comment

# 需要导入模块: from ckan.plugins import toolkit [as 别名]
# 或者: from ckan.plugins.toolkit import get_action [as 别名]
def validate_comment(context, request_data):
    comment = request_data.get('comment', '')

    # Check if the data request exists
    try:
        datarequest = tk.get_action(constants.SHOW_DATAREQUEST)(context, {'id': request_data['datarequest_id']})
    except Exception:
        raise tk.ValidationError({tk._('Data Request'): [tk._('Data Request not found')]})

    if not comment or len(comment) <= 0:
        raise tk.ValidationError({tk._('Comment'): [tk._('Comments must be a minimum of 1 character long')]})

    if len(comment) > constants.COMMENT_MAX_LENGTH:
        raise tk.ValidationError({tk._('Comment'): [tk._('Comments must be a maximum of %d characters long') % constants.COMMENT_MAX_LENGTH]})

    return datarequest 
开发者ID:conwetlab,项目名称:ckanext-datarequests,代码行数:18,代码来源:validator.py

示例14: acquired_datasets

# 需要导入模块: from ckan.plugins import toolkit [as 别名]
# 或者: from ckan.plugins.toolkit import get_action [as 别名]
def acquired_datasets():
    context = {'auth_user_obj': g.userobj, 'for_view': True, 'model': model, 'session': model.Session, 'user': g.user}
    data_dict = {'user_obj': g.userobj}
    try:
        user_dict = toolkit.get_action('user_show')(context, data_dict)
        acquired_datasets = toolkit.get_action(constants.ACQUISITIONS_LIST)(context, None)
    except logic.NotFound:
        base.abort(404, _('User not found'))
    except logic.NotAuthorized:
        base.abort(403, _('Not authorized to see this page'))

    extra_vars = {
        'user_dict': user_dict,
        'acquired_datasets': acquired_datasets,
    }
    return base.render('user/dashboard_acquired.html', extra_vars) 
开发者ID:conwetlab,项目名称:ckanext-privatedatasets,代码行数:18,代码来源:views.py

示例15: private_datasets_metadata_checker

# 需要导入模块: from ckan.plugins import toolkit [as 别名]
# 或者: from ckan.plugins.toolkit import get_action [as 别名]
def private_datasets_metadata_checker(key, data, errors, context):

    dataset_id = data.get(('id',))
    private_val = data.get(('private',))

    # Avoid missing value
    # "if not private_val:" is not valid because private_val can be False
    if not isinstance(private_val, six.string_types) and not isinstance(private_val, bool):
        private_val = None

    # If the private field is not included in the data dict, we must check the current value
    if private_val is None and dataset_id:
        dataset_dict = toolkit.get_action('package_show')({'ignore_auth': True}, {'id': dataset_id})
        private_val = dataset_dict.get('private')

    private = private_val is True if isinstance(private_val, bool) else private_val == 'True'
    metadata_value = data[key]

    # If allowed users are included and the dataset is not private outside and organization, an error will be raised.
    if metadata_value and not private:
        errors[key].append(_('This field is only valid when you create a private dataset')) 
开发者ID:conwetlab,项目名称:ckanext-privatedatasets,代码行数:23,代码来源:converters_validators.py


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