Ejemplo n.º 1
0
def register_group_blueprints(app):
    """
    Register a Flask blueprint for the various IGroupForm instances.

    It will register blueprints for both groups and organizations
    """

    from ckan.views.group import group, register_group_plugin_rules

    for plugin in plugins.PluginImplementations(plugins.IGroupForm):

        # Get group_controller from plugin if there is one,
        # otherwise use 'group'
        try:
            group_controller = plugin.group_controller()
        except AttributeError:
            group_controller = 'group'

        if hasattr(plugin, 'is_organization'):
            is_organization = plugin.is_organization
        else:
            is_organization = group_controller == 'organization'

        for group_type in plugin.group_types():

            if group_type in (u'group', u'organization'):
                # The default routes are registered with the core
                # 'group' or 'organization' blueprint
                continue
            elif group_type in app.blueprints:
                raise ValueError(
                    'A blueprint for has already been associated for the '
                    'group type {}'.format(group_type))

            blueprint = Blueprint(group_type,
                                  group.import_name,
                                  url_prefix='/{}'.format(group_type),
                                  url_defaults={
                                      u'group_type': group_type,
                                      u'is_organization': is_organization
                                  })
            if hasattr(plugin, 'prepare_group_blueprint'):
                blueprint = plugin.prepare_group_blueprint(
                    group_type, blueprint)
            register_group_plugin_rules(blueprint)
            toolkit.signals.register_blueprint.send(
                u"organization" if is_organization else u"group",
                blueprint=blueprint)
            app.register_blueprint(blueprint)
Ejemplo n.º 2
0
def register_group_blueprints(app):
    """
    Register a Flask blueprint for the various IGroupForm instances.

    It will register blueprints for both groups and organizations
    """

    from ckan.views.group import group, register_group_plugin_rules

    for plugin in plugins.PluginImplementations(plugins.IGroupForm):

        # Get group_controller from plugin if there is one,
        # otherwise use 'group'
        try:
            group_controller = plugin.group_controller()
        except AttributeError:
            group_controller = 'group'

        if hasattr(plugin, 'is_organization'):
            is_organization = plugin.is_organization
        else:
            is_organization = group_controller == 'organization'

        for group_type in plugin.group_types():

            if group_type in (u'group', u'organization'):
                # The default routes are registered with the core
                # 'group' or 'organization' blueprint
                continue
            elif group_type in app.blueprints:
                raise ValueError(
                    'A blueprint for has already been associated for the '
                    'group type {}'.format(group_type))

            blueprint = Blueprint(group_type,
                                  group.import_name,
                                  url_prefix='/{}'.format(group_type),
                                  url_defaults={u'group_type': group_type,
                                                u'is_organization': is_organization})
            register_group_plugin_rules(blueprint)
            app.register_blueprint(blueprint)
Ejemplo n.º 3
0
def register_group_plugins(app):
    """
    Register the various IGroupForm instances.

    This method will setup the mappings between group types and the
    registered IGroupForm instances. If it's called more than once an
    exception will be raised.

    It will register IGroupForm instances for both groups and organizations
    """
    global _default_group_plugin
    global _default_organization_plugin

    from ckan.views.group import group, register_group_plugin_rules
    # Create the mappings and register the fallback behaviour if one is found.
    for plugin in plugins.PluginImplementations(plugins.IGroupForm):

        # Get group_controller from plugin if there is one,
        # otherwise use 'group'
        try:
            group_controller = plugin.group_controller()
        except AttributeError:
            group_controller = 'group'

        if hasattr(plugin, 'is_organization'):
            is_organization = plugin.is_organization
        else:
            is_organization = group_controller == 'organization'

        if plugin.is_fallback():

            if is_organization:
                if _default_organization_plugin is not None and \
                   not isinstance(_default_organization_plugin, DefaultOrganizationForm):
                    raise ValueError("More than one fallback IGroupForm for "
                                     "organizations has been registered")
                _default_organization_plugin = plugin

            else:
                if _default_group_plugin is not None and \
                   not isinstance(_default_group_plugin, DefaultGroupForm):
                    raise ValueError("More than one fallback IGroupForm for "
                                     "groups has been registered")
                _default_group_plugin = plugin

        for group_type in plugin.group_types():

            if group_type in (u'group', u'organization'):
                # The default routes are registered with the core
                # 'group' or 'organization' blueprint
                _group_plugins[group_type] = plugin
                continue
            elif group_type in _group_plugins:
                raise ValueError("An existing IGroupForm is "
                                 "already associated with the group type "
                                 "'%s'" % group_type)
            _group_plugins[group_type] = plugin
            _group_controllers[group_type] = group_controller

            blueprint = Blueprint(group_type,
                                  group.import_name,
                                  url_prefix='/{}'.format(group_type),
                                  url_defaults={
                                      u'group_type': group_type,
                                      u'is_organization': is_organization
                                  })
            register_group_plugin_rules(blueprint)
            app.register_blueprint(blueprint)

        set_default_group_plugin()
Ejemplo n.º 4
0
def register_group_plugins(app):
    """
    Register the various IGroupForm instances.

    This method will setup the mappings between group types and the
    registered IGroupForm instances. If it's called more than once an
    exception will be raised.

    It will register IGroupForm instances for both groups and organizations
    """
    global _default_group_plugin
    global _default_organization_plugin

    from ckan.views.group import group, register_group_plugin_rules
    # Create the mappings and register the fallback behaviour if one is found.
    for plugin in plugins.PluginImplementations(plugins.IGroupForm):

        # Get group_controller from plugin if there is one,
        # otherwise use 'group'
        try:
            group_controller = plugin.group_controller()
        except AttributeError:
            group_controller = 'group'

        if hasattr(plugin, 'is_organization'):
            is_organization = plugin.is_organization
        else:
            is_organization = group_controller == 'organization'

        if plugin.is_fallback():

            if is_organization:
                if _default_organization_plugin is not None and \
                   not isinstance(_default_organization_plugin, DefaultOrganizationForm):
                        raise ValueError("More than one fallback IGroupForm for "
                                         "organizations has been registered")
                _default_organization_plugin = plugin

            else:
                if _default_group_plugin is not None and \
                   not isinstance(_default_group_plugin, DefaultGroupForm):
                        raise ValueError("More than one fallback IGroupForm for "
                                         "groups has been registered")
                _default_group_plugin = plugin

        for group_type in plugin.group_types():

            if group_type in (u'group', u'organization'):
                # The default routes are registered with the core
                # 'group' or 'organization' blueprint
                _group_plugins[group_type] = plugin
                continue
            elif group_type in _group_plugins:
                raise ValueError("An existing IGroupForm is "
                                 "already associated with the group type "
                                 "'%s'" % group_type)
            _group_plugins[group_type] = plugin
            _group_controllers[group_type] = group_controller

            blueprint = Blueprint(group_type,
                                  group.import_name,
                                  url_prefix='/{}'.format(group_type),
                                  url_defaults={u'group_type': group_type,
                                                u'is_organization': is_organization})
            register_group_plugin_rules(blueprint)
            app.register_blueprint(blueprint)

        set_default_group_plugin()