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


Python plugins.PluginImplementations方法代码示例

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


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

示例1: login

# 需要导入模块: from ckan import plugins [as 别名]
# 或者: from ckan.plugins import PluginImplementations [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,项目名称:daf-recipes,代码行数:25,代码来源:user.py

示例2: handle_request

# 需要导入模块: from ckan import plugins [as 别名]
# 或者: from ckan.plugins import PluginImplementations [as 别名]
def handle_request(request, tmpl_context):
    ''' Set the language for the request '''
    lang = request.environ.get('CKAN_LANG') or \
        config.get('ckan.locale_default', 'en')
    if lang != 'en':
        set_lang(lang)

    for plugin in PluginImplementations(ITranslation):
        if lang in plugin.i18n_locales():
            _add_extra_translations(plugin.i18n_directory(), lang,
                                    plugin.i18n_domain())

    extra_directory = config.get('ckan.i18n.extra_directory')
    extra_domain = config.get('ckan.i18n.extra_gettext_domain')
    extra_locales = aslist(config.get('ckan.i18n.extra_locales'))
    if extra_directory and extra_domain and extra_locales:
        if lang in extra_locales:
            _add_extra_translations(extra_directory, lang, extra_domain)

    tmpl_context.language = lang
    return lang 
开发者ID:italia,项目名称:daf-recipes,代码行数:23,代码来源:i18n.py

示例3: abort

# 需要导入模块: from ckan import plugins [as 别名]
# 或者: from ckan.plugins import PluginImplementations [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,项目名称:daf-recipes,代码行数:26,代码来源:base.py

示例4: tag_list_dictize

# 需要导入模块: from ckan import plugins [as 别名]
# 或者: from ckan.plugins import PluginImplementations [as 别名]
def tag_list_dictize(tag_list, context):

    result_list = []
    for tag in tag_list:
        if context.get('with_capacity'):
            tag, capacity = tag
            dictized = d.table_dictize(tag, context, capacity=capacity)
        else:
            dictized = d.table_dictize(tag, context)

        # Add display_names to tag dicts. At first a tag's display_name is just
        # the same as its name, but the display_name might get changed later
        # (e.g.  translated into another language by the multilingual
        # extension).
        assert not dictized.has_key('display_name')
        dictized['display_name'] = dictized['name']

        if context.get('for_view'):
            for item in plugins.PluginImplementations(
                    plugins.ITagController):
                dictized = item.before_view(dictized)

        result_list.append(dictized)

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

示例5: test_loading_datastore_last_doesnt_work

# 需要导入模块: from ckan import plugins [as 别名]
# 或者: from ckan.plugins import PluginImplementations [as 别名]
def test_loading_datastore_last_doesnt_work(self):
        # This test is complicated because we can't import
        # ckanext.datastore.plugin before running it. If we did so, the
        # DatastorePlugin class would be parsed which breaks the reason of our
        # test.
        p.load('sample_datastore_plugin')
        thrown_exception = None
        try:
            p.load('datastore')
        except Exception as e:
            thrown_exception = e
        idatastores = [x.__class__.__name__ for x
                       in p.PluginImplementations(interfaces.IDatastore)]
        p.unload('sample_datastore_plugin')

        assert thrown_exception is not None, \
            ('Loading "datastore" after another IDatastore plugin was'
             'loaded should raise DatastoreException')
        assert_equal(thrown_exception.__class__.__name__,
                     plugin.DatastoreException.__name__)
        assert plugin.DatastorePlugin.__name__ not in idatastores, \
            ('You shouldn\'t be able to load the "datastore" plugin after'
             'another IDatastore plugin was loaded') 
开发者ID:italia,项目名称:daf-recipes,代码行数:25,代码来源:test_plugin.py

示例6: harvest_source_type_exists

# 需要导入模块: from ckan import plugins [as 别名]
# 或者: from ckan.plugins import PluginImplementations [as 别名]
def harvest_source_type_exists(value, context):
    # TODO: use new description interface

    # Get all the registered harvester types
    available_types = []
    for harvester in PluginImplementations(IHarvester):
        info = harvester.info()
        if not info or 'name' not in info:
            log.error('Harvester %s does not provide the harvester name in '
                      'the info response' % harvester)
            continue
        available_types.append(info['name'])

    if not value in available_types:
        raise Invalid('Unknown harvester type: %s. Registered types: %r' %
                      (value, available_types))

    return value 
开发者ID:italia,项目名称:daf-recipes,代码行数:20,代码来源:validators.py

示例7: download_and_extract

# 需要导入模块: from ckan import plugins [as 别名]
# 或者: from ckan.plugins import PluginImplementations [as 别名]
def download_and_extract(resource_url):
    """
    Download resource and extract metadata using Solr.

    The extracted metadata is cleaned and returned.
    """
    session = Session()
    request = Request('GET', resource_url).prepare()
    for plugin in PluginImplementations(IExtractorRequest):
        request = plugin.extractor_before_request(request)
    with tempfile.NamedTemporaryFile() as f:
        r = session.send(request, stream=True)
        r.raise_for_status()
        for chunk in r.iter_content(chunk_size=1024):
            f.write(chunk)
        f.flush()
        f.seek(0)
        data = pysolr.Solr(config['solr_url']).extract(f, extractFormat='text')
    data['metadata']['fulltext'] = data['contents']
    return dict(clean_metadatum(*x) for x in data['metadata'].iteritems()) 
开发者ID:stadt-karlsruhe,项目名称:ckanext-extractor,代码行数:22,代码来源:lib.py

示例8: _handle_validation_for_resource

# 需要导入模块: from ckan import plugins [as 别名]
# 或者: from ckan.plugins import PluginImplementations [as 别名]
def _handle_validation_for_resource(self, context, resource):
        needs_validation = False
        if ((
            # File uploaded
            resource.get(u'url_type') == u'upload' or
            # URL defined
            resource.get(u'url')
            ) and (
            # Make sure format is supported
            resource.get(u'format', u'').lower() in
                settings.SUPPORTED_FORMATS
                )):
            needs_validation = True

        if needs_validation:

            for plugin in p.PluginImplementations(IDataValidation):
                if not plugin.can_validate(context, resource):
                    log.debug('Skipping validation for resource {}'.format(resource['id']))
                    return

            _run_async_validation(resource[u'id']) 
开发者ID:frictionlessdata,项目名称:ckanext-validation,代码行数:24,代码来源:plugin.py

示例9: _get_validator

# 需要导入模块: from ckan import plugins [as 别名]
# 或者: from ckan.plugins import PluginImplementations [as 别名]
def _get_validator(self):
        '''
        Returns the validator object using the relevant profiles

        The profiles to be used are assigned in the following order:

        1. 'validator_profiles' property of the harvest source config object
        2. 'ckan.spatial.validator.profiles' configuration option in the ini file
        3. Default value as defined in DEFAULT_VALIDATOR_PROFILES
        '''
        if not hasattr(self, '_validator'):
            if hasattr(self, 'source_config') and self.source_config.get('validator_profiles', None):
                profiles = self.source_config.get('validator_profiles')
            elif config.get('ckan.spatial.validator.profiles', None):
                profiles = [
                    x.strip() for x in
                    config.get('ckan.spatial.validator.profiles').split(',')
                ]
            else:
                profiles = DEFAULT_VALIDATOR_PROFILES
            self._validator = Validators(profiles=profiles)

            # Add any custom validators from extensions
            for plugin_with_validators in p.PluginImplementations(ISpatialHarvester):
                custom_validators = plugin_with_validators.get_validators()
                for custom_validator in custom_validators:
                    if custom_validator not in all_validators:
                        self._validator.add_validator(custom_validator)


        return self._validator 
开发者ID:italia,项目名称:daf-recipes,代码行数:33,代码来源:base.py

示例10: startContext

# 需要导入模块: from ckan import plugins [as 别名]
# 或者: from ckan.plugins import PluginImplementations [as 别名]
def startContext(self, ctx):
        # import needs to be here or setup happens too early
        import ckan.model as model

        if 'legacy' not in repr(ctx):
            # We don't want to do the stuff below for new-style tests.
            if not CkanNose.settings.reset_database:
                model.repo.tables_created_and_initialised = True
            return

        if isclass(ctx):
            if hasattr(ctx, "no_db") and ctx.no_db:
                return
            if (not CkanNose.settings.reset_database
                    and not CkanNose.settings.ckan_migration):
                model.Session.close_all()
                model.repo.tables_created_and_initialised = True
                model.repo.rebuild_db()
                self.is_first_test = False
            elif self.is_first_test or CkanNose.settings.ckan_migration:
                model.Session.close_all()
                model.repo.clean_db()
                self.is_first_test = False
                if CkanNose.settings.ckan_migration:
                    model.Session.close_all()
                    model.repo.upgrade_db()

            ## This is to make sure the configuration is run again.
            ## Plugins use configure to make their own tables and they
            ## may need to be recreated to make tests work.
            from ckan.plugins import PluginImplementations
            from ckan.plugins.interfaces import IConfigurable
            for plugin in PluginImplementations(IConfigurable):
                plugin.configure(config)

            # init_db is run at the start of every class because
            # when you use an in-memory sqlite db, it appears that
            # the db is destroyed after every test when you Session.Remove().
            model.repo.init_db() 
开发者ID:italia,项目名称:daf-recipes,代码行数:41,代码来源:ckan_nose_plugin.py

示例11: notify_observers

# 需要导入模块: from ckan import plugins [as 别名]
# 或者: from ckan.plugins import PluginImplementations [as 别名]
def notify_observers(self, func):
        """
        Call func(observer) for all registered observers.

        :param func: Any callable, which will be called for each observer
        :returns: EXT_CONTINUE if no errors encountered, otherwise EXT_STOP
        """
        for observer in plugins.PluginImplementations(plugins.IMapper):
            func(observer) 
开发者ID:italia,项目名称:daf-recipes,代码行数:11,代码来源:extension.py

示例12: notify_observers

# 需要导入模块: from ckan import plugins [as 别名]
# 或者: from ckan.plugins import PluginImplementations [as 别名]
def notify_observers(self, session, method):
        session.flush()
        if not hasattr(session, '_object_cache'):
            return

        obj_cache = session._object_cache
        new = obj_cache['new']
        changed = obj_cache['changed']
        deleted = obj_cache['deleted']

        for obj in set(new):
            if isinstance(obj, (_package.Package, resource.Resource)):
                method(obj, domain_object.DomainObjectOperation.new)
        for obj in set(deleted):
            if isinstance(obj, (_package.Package, resource.Resource)):
                method(obj, domain_object.DomainObjectOperation.deleted)
        for obj in set(changed):
            if isinstance(obj, resource.Resource):
                method(obj, domain_object.DomainObjectOperation.changed)
            if getattr(obj, 'url_changed', False):
                for item in plugins.PluginImplementations(plugins.IResourceUrlChange):
                    item.notify(obj)

        changed_pkgs = set(obj for obj in changed
                           if isinstance(obj, _package.Package))

        for obj in new | changed | deleted:
            if not isinstance(obj, _package.Package):
                try:
                    related_packages = obj.related_packages()
                except AttributeError:
                    continue
                # this is needed to sort out vdm bug where pkg.as_dict does not
                # work when the package is deleted.
                for package in related_packages:
                    if package and package not in deleted | new:
                        changed_pkgs.add(package)
        for obj in changed_pkgs:
            method(obj, domain_object.DomainObjectOperation.changed) 
开发者ID:italia,项目名称:daf-recipes,代码行数:41,代码来源:modification.py

示例13: notify

# 需要导入模块: from ckan import plugins [as 别名]
# 或者: from ckan.plugins import PluginImplementations [as 别名]
def notify(self, entity, operation):
        for observer in plugins.PluginImplementations(
                plugins.IDomainObjectModification):
            try:
                observer.notify(entity, operation)
            except SearchIndexError, search_error:
                log.exception(search_error)
                # Reraise, since it's pretty crucial to ckan if it can't index
                # a dataset
                raise
            except Exception, ex:
                log.exception(ex)
                # Don't reraise other exceptions since they are generally of
                # secondary importance so shouldn't disrupt the commit. 
开发者ID:italia,项目名称:daf-recipes,代码行数:16,代码来源:modification.py

示例14: notify_after_commit

# 需要导入模块: from ckan import plugins [as 别名]
# 或者: from ckan.plugins import PluginImplementations [as 别名]
def notify_after_commit(self, entity, operation):
        for observer in plugins.PluginImplementations(
                plugins.IDomainObjectModification):
            try:
                observer.notify_after_commit(entity, operation)
            except SearchIndexError, search_error:
                log.exception(search_error)
                # Reraise, since it's pretty crucial to ckan if it can't index
                # a dataset
                raise
            except Exception, ex:
                log.exception(ex)
                # Don't reraise other exceptions since they are generally of
                # secondary importance so shouldn't disrupt the commit. 
开发者ID:italia,项目名称:daf-recipes,代码行数:16,代码来源:modification.py

示例15: get_validator

# 需要导入模块: from ckan import plugins [as 别名]
# 或者: from ckan.plugins import PluginImplementations [as 别名]
def get_validator(validator):
    '''Return a validator function by name.

    :param validator: the name of the validator function to return,
        eg. ``'package_name_exists'``
    :type validator: string

    :raises: :py:exc:`~ckan.plugins.toolkit.UnknownValidator` if the named
        validator is not found

    :returns: the named validator function
    :rtype: ``types.FunctionType``

    '''
    if not _validators_cache:
        validators = _import_module_functions('ckan.lib.navl.validators')
        _validators_cache.update(validators)
        validators = _import_module_functions('ckan.logic.validators')
        _validators_cache.update(validators)
        _validators_cache.update({'OneOf': formencode.validators.OneOf})
        converters = _import_module_functions('ckan.logic.converters')
        _validators_cache.update(converters)

        for plugin in p.PluginImplementations(p.IValidators):
            for name, fn in plugin.get_validators().items():
                if name in _validators_cache:
                    raise NameConflict(
                        'The validator %r is already defined' % (name,)
                    )
                log.debug('Validator function {0} from plugin {1} was inserted'
                          .format(name, plugin.name))
                _validators_cache[name] = fn
    try:
        return _validators_cache[validator]
    except KeyError:
        raise UnknownValidator('Validator `%s` does not exist' % validator) 
开发者ID:italia,项目名称:daf-recipes,代码行数:38,代码来源:__init__.py


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