コード例 #1
0
ファイル: plugins.py プロジェクト: tino097/ckan
def register_package_blueprints(app: 'CKANFlask') -> None:
    """
    Register a Flask blueprint for the various IDatasetForm instances.

    Actually two blueprints per IDatasetForm instance, one for the dataset routes
    and one for the resources one.
    """

    from ckan.views.dataset import dataset, register_dataset_plugin_rules
    from ckan.views.resource import resource, register_dataset_plugin_rules as dataset_resource_rules

    # Create the mappings and register the fallback behaviour if one is found.
    for plugin in plugins.PluginImplementations(plugins.IDatasetForm):
        for package_type in plugin.package_types():

            if package_type == u'dataset':
                # The default routes are registered with the core
                # 'dataset' blueprint
                continue

            elif package_type in app.blueprints:
                raise ValueError(
                    'A blueprint for has already been associated for the '
                    'package type {}'.format(package_type))

            dataset_blueprint = Blueprint(
                package_type,
                dataset.import_name,
                url_prefix='/{}'.format(package_type),
                url_defaults={'package_type': package_type})
            if hasattr(plugin, 'prepare_dataset_blueprint'):
                dataset_blueprint = plugin.prepare_dataset_blueprint(
                    package_type,
                    dataset_blueprint)
            register_dataset_plugin_rules(dataset_blueprint)

            signals.register_blueprint.send(
                u"dataset", blueprint=dataset_blueprint)
            app.register_blueprint(dataset_blueprint)

            resource_blueprint = Blueprint(
                u'{}_resource'.format(package_type),
                resource.import_name,
                url_prefix=u'/{}/<id>/resource'.format(package_type),
                url_defaults={u'package_type': package_type})
            if hasattr(plugin, 'prepare_resource_blueprint'):
                resource_blueprint = plugin.prepare_resource_blueprint(
                    package_type,
                    resource_blueprint)
            dataset_resource_rules(resource_blueprint)
            signals.register_blueprint.send(
                u"resource", blueprint=resource_blueprint)
            app.register_blueprint(resource_blueprint)
            log.debug(
                'Registered blueprints for custom dataset type \'{}\''.format(
                    package_type))
コード例 #2
0
ファイル: plugins.py プロジェクト: zznamtran123/ckan
def register_package_plugins(app):
    """
    Register the various IDatasetForm instances.

    This method will setup the mappings between package types and the
    registered IDatasetForm instances. If it's called more than once an
    exception will be raised.
    """
    global _default_package_plugin

    from ckan.views.dataset import dataset, register_dataset_plugin_rules
    from ckan.views.resource import resource, register_dataset_plugin_rules as dataset_resource_rules

    # Create the mappings and register the fallback behaviour if one is found.
    for plugin in plugins.PluginImplementations(plugins.IDatasetForm):
        if plugin.is_fallback():
            if _default_package_plugin is not None and not isinstance(
                    _default_package_plugin, DefaultDatasetForm):
                raise ValueError("More than one fallback "
                                 "IDatasetForm has been registered")
            _default_package_plugin = plugin
        for package_type in plugin.package_types():

            if package_type == u'dataset':
                # The default routes are registered with the core
                # 'dataset' blueprint
                continue

            elif package_type in _package_plugins:
                raise ValueError("An existing IDatasetForm is "
                                 "already associated with the package type "
                                 "'%s'" % package_type)

            _package_plugins[package_type] = plugin

            dataset_blueprint = Blueprint(
                package_type,
                dataset.import_name,
                url_prefix='/{}'.format(package_type),
                url_defaults={'package_type': package_type})
            register_dataset_plugin_rules(dataset_blueprint)
            app.register_blueprint(dataset_blueprint)

            resource_blueprint = Blueprint(
                u'{}_resource'.format(package_type),
                resource.import_name,
                url_prefix=u'/{}/<id>/resource'.format(package_type),
                url_defaults={u'package_type': package_type})
            dataset_resource_rules(resource_blueprint)
            app.register_blueprint(resource_blueprint)

    # Setup the fallback behaviour if one hasn't been defined.
    set_default_package_plugin()
コード例 #3
0
ファイル: plugins.py プロジェクト: jqnatividad/ckan
def register_package_plugins(app):
    """
    Register the various IDatasetForm instances.

    This method will setup the mappings between package types and the
    registered IDatasetForm instances. If it's called more than once an
    exception will be raised.
    """
    global _default_package_plugin

    from ckan.views.dataset import dataset, register_dataset_plugin_rules
    from ckan.views.resource import resource, register_dataset_plugin_rules as dataset_resource_rules

    # Create the mappings and register the fallback behaviour if one is found.
    for plugin in plugins.PluginImplementations(plugins.IDatasetForm):
        if plugin.is_fallback():
            if _default_package_plugin is not None and not isinstance(_default_package_plugin, DefaultDatasetForm):
                raise ValueError("More than one fallback "
                                 "IDatasetForm has been registered")
            _default_package_plugin = plugin
        for package_type in plugin.package_types():

            if package_type == u'dataset':
                # The default routes are registered with the core
                # 'dataset' blueprint
                continue

            elif package_type in _package_plugins:
                raise ValueError("An existing IDatasetForm is "
                                 "already associated with the package type "
                                 "'%s'" % package_type)

            _package_plugins[package_type] = plugin

            dataset_blueprint = Blueprint(
                package_type,
                dataset.import_name,
                url_prefix='/{}'.format(package_type),
                url_defaults={'package_type': package_type})
            register_dataset_plugin_rules(dataset_blueprint)
            app.register_blueprint(dataset_blueprint)

            resource_blueprint = Blueprint(
                u'{}_resource'.format(package_type),
                resource.import_name,
                url_prefix=u'/{}/<id>/resource'.format(package_type),
                url_defaults={u'package_type': package_type})
            dataset_resource_rules(resource_blueprint)
            app.register_blueprint(resource_blueprint)

    # Setup the fallback behaviour if one hasn't been defined.
    set_default_package_plugin()
コード例 #4
0
ファイル: plugins.py プロジェクト: mattbis/ckan
def register_package_blueprints(app):
    """
    Register a Flask blueprint for the various IDatasetForm instances.

    Actually two blueprints per IDatasetForm instance, one for the dataset routes
    and one for the resources one.
    """

    from ckan.views.dataset import dataset, register_dataset_plugin_rules
    from ckan.views.resource import resource, register_dataset_plugin_rules as dataset_resource_rules

    # Create the mappings and register the fallback behaviour if one is found.
    for plugin in plugins.PluginImplementations(plugins.IDatasetForm):
        for package_type in plugin.package_types():

            if package_type == u'dataset':
                # The default routes are registered with the core
                # 'dataset' blueprint
                continue

            elif package_type in app.blueprints:
                raise ValueError(
                    'A blueprint for has already been associated for the '
                    'package type {}'.format(package_type))

            dataset_blueprint = Blueprint(
                package_type,
                dataset.import_name,
                url_prefix='/{}'.format(package_type),
                url_defaults={'package_type': package_type})
            register_dataset_plugin_rules(dataset_blueprint)
            app.register_blueprint(dataset_blueprint)

            resource_blueprint = Blueprint(
                u'{}_resource'.format(package_type),
                resource.import_name,
                url_prefix=u'/{}/<id>/resource'.format(package_type),
                url_defaults={u'package_type': package_type})
            dataset_resource_rules(resource_blueprint)
            app.register_blueprint(resource_blueprint)
            log.debug(
                'Registered blueprints for custom dataset type \'{}\''.format(
                    package_type))