Exemplo n.º 1
0
def register_group_plugins(map):
    """
    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.
    """
    global _default_group_plugin

    # This function should have not effect if called more than once.
    # This should not occur in normal deployment, but it may happen when
    # running unit tests.
    if _default_group_plugin is not None:
        return

    # Create the mappings and register the fallback behaviour if one is found.
    for plugin in plugins.PluginImplementations(plugins.IGroupForm):
        if plugin.is_fallback():
            if _default_group_plugin is not None:
                raise ValueError("More than one fallback IGroupForm has been "
                                 "registered")
            _default_group_plugin = plugin

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

        for group_type in plugin.group_types():
            # Create the routes based on group_type here, this will
            # allow us to have top level objects that are actually
            # Groups, but first we need to make sure we are not
            # clobbering an existing domain

            # Our version of routes doesn't allow the environ to be
            # passed into the match call and so we have to set it on the
            # map instead. This looks like a threading problem waiting
            # to happen but it is executed sequentially from inside the
            # routing setup

            map.connect('%s_index' % group_type,
                        '/%s' % group_type,
                        controller=group_controller,
                        action='index')
            map.connect('%s_new' % group_type,
                        '/%s/new' % group_type,
                        controller=group_controller,
                        action='new')
            map.connect('%s_read' % group_type,
                        '/%s/{id}' % group_type,
                        controller=group_controller,
                        action='read')
            map.connect('%s_action' % group_type,
                        '/%s/{action}/{id}' % group_type,
                        controller=group_controller,
                        requirements=dict(action='|'.join([
                            'edit', 'authz', 'delete', 'history', 'member_new',
                            'member_delete', 'followers', 'follow', 'unfollow',
                            'admins', 'activity'
                        ])))
            map.connect('%s_edit' % group_type,
                        '/%s/edit/{id}' % group_type,
                        controller=group_controller,
                        action='edit',
                        ckan_icon='edit')
            map.connect('%s_members' % group_type,
                        '/%s/members/{id}' % group_type,
                        controller=group_controller,
                        action='members',
                        ckan_icon='group')
            map.connect('%s_activity' % group_type,
                        '/%s/activity/{id}/{offset}' % group_type,
                        controller=group_controller,
                        action='activity',
                        ckan_icon='time'),
            map.connect('%s_about' % group_type,
                        '/%s/about/{id}' % group_type,
                        controller=group_controller,
                        action='about',
                        ckan_icon='info-sign')
            map.connect('%s_bulk_process' % group_type,
                        '/%s/bulk_process/{id}' % group_type,
                        controller=group_controller,
                        action='bulk_process',
                        ckan_icon='sitemap')

            if 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

            controller_obj = None
            # If using one of the default controllers, tell it that it is allowed
            # to handle other group_types.
            # Import them here to avoid circular imports.
            if group_controller == 'group':
                from ckan.controllers.group import GroupController as controller_obj
            elif group_controller == 'organization':
                from ckan.controllers.organization import OrganizationController as controller_obj
            if controller_obj is not None:
                controller_obj.add_group_type(group_type)

    # Setup the fallback behaviour if one hasn't been defined.
    if _default_group_plugin is None:
        _default_group_plugin = DefaultGroupForm()
    if 'group' not in _group_controllers:
        _group_controllers['group'] = 'group'
    if 'organization' not in _group_controllers:
        _group_controllers['organization'] = 'organization'
Exemplo n.º 2
0
def register_group_plugins(map):
    """
    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.
    """
    global _default_group_plugin

    # This function should have not effect if called more than once.
    # This should not occur in normal deployment, but it may happen when
    # running unit tests.
    if _default_group_plugin is not None:
        return

    # Create the mappings and register the fallback behaviour if one is found.
    for plugin in plugins.PluginImplementations(plugins.IGroupForm):
        if plugin.is_fallback():
            if _default_group_plugin is not None:
                raise ValueError("More than one fallback IGroupForm has been "
                                 "registered")
            _default_group_plugin = plugin

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

        for group_type in plugin.group_types():
            # Create the routes based on group_type here, this will
            # allow us to have top level objects that are actually
            # Groups, but first we need to make sure we are not
            # clobbering an existing domain

            # Our version of routes doesn't allow the environ to be
            # passed into the match call and so we have to set it on the
            # map instead. This looks like a threading problem waiting
            # to happen but it is executed sequentially from inside the
            # routing setup

            map.connect('%s_index' % group_type, '/%s' % group_type,
                        controller=group_controller, action='index')
            map.connect('%s_new' % group_type, '/%s/new' % group_type,
                        controller=group_controller, action='new')
            map.connect('%s_read' % group_type, '/%s/{id}' % group_type,
                        controller=group_controller, action='read')
            map.connect('%s_action' % group_type,
                        '/%s/{action}/{id}' % group_type,
                        controller=group_controller,
                        requirements=dict(action='|'.join(
                            ['edit', 'authz', 'delete', 'history', 'member_new',
                             'member_delete', 'followers', 'follow',
                             'unfollow', 'admins', 'activity'])))
            map.connect('%s_edit' % group_type, '/%s/edit/{id}' % group_type,
                        controller=group_controller, action='edit',
                        ckan_icon='edit')
            map.connect('%s_members' % group_type,
                        '/%s/members/{id}' % group_type,
                        controller=group_controller,
                        action='members',
                        ckan_icon='group')
            map.connect('%s_activity' % group_type,
                        '/%s/activity/{id}/{offset}' % group_type,
                        controller=group_controller,
                        action='activity', ckan_icon='time'),
            map.connect('%s_about' % group_type, '/%s/about/{id}' % group_type,
                        controller=group_controller,
                        action='about', ckan_icon='info-sign')
            map.connect('%s_bulk_process' % group_type,
                        '/%s/bulk_process/{id}' % group_type,
                        controller=group_controller,
                        action='bulk_process', ckan_icon='sitemap')

            if 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

            controller_obj = None
            # If using one of the default controllers, tell it that it is allowed
            # to handle other group_types.
            # Import them here to avoid circular imports.
            if group_controller == 'group':
                from ckan.controllers.group import GroupController as controller_obj
            elif group_controller == 'organization':
                from ckan.controllers.organization import OrganizationController as controller_obj
            if controller_obj is not None:
                controller_obj.add_group_type(group_type)

    # Setup the fallback behaviour if one hasn't been defined.
    if _default_group_plugin is None:
        _default_group_plugin = DefaultGroupForm()
    if 'group' not in _group_controllers:
        _group_controllers['group'] = 'group'
    if 'organization' not in _group_controllers:
        _group_controllers['organization'] = 'organization'
Exemplo n.º 3
0
def register_group_plugins(map):
    """
    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.
    """
    global _default_group_plugin

    # This function should have not effect if called more than once.
    # This should not occur in normal deployment, but it may happen when
    # running unit tests.
    if _default_group_plugin is not None:
        return

    # Create the mappings and register the fallback behaviour if one is found.
    for plugin in plugins.PluginImplementations(plugins.IGroupForm):
        if plugin.is_fallback():
            if _default_group_plugin is not None:
                raise ValueError("More than one fallback IGroupForm has been " "registered")
            _default_group_plugin = plugin

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

        for group_type in plugin.group_types():
            # Create the routes based on group_type here, this will
            # allow us to have top level objects that are actually
            # Groups, but first we need to make sure we are not
            # clobbering an existing domain

            # Our version of routes doesn't allow the environ to be
            # passed into the match call and so we have to set it on the
            # map instead. This looks like a threading problem waiting
            # to happen but it is executed sequentially from inside the
            # routing setup

            map.connect("%s_index" % group_type, "/%s" % group_type, controller=group_controller, action="index")
            map.connect("%s_new" % group_type, "/%s/new" % group_type, controller=group_controller, action="new")
            map.connect("%s_read" % group_type, "/%s/{id}" % group_type, controller=group_controller, action="read")
            map.connect(
                "%s_action" % group_type,
                "/%s/{action}/{id}" % group_type,
                controller=group_controller,
                requirements=dict(
                    action="|".join(
                        [
                            "edit",
                            "authz",
                            "history",
                            "member_new",
                            "member_delete",
                            "followers",
                            "follow",
                            "unfollow",
                            "admins",
                            "activity",
                        ]
                    )
                ),
            )
            map.connect(
                "%s_edit" % group_type,
                "/%s/edit/{id}" % group_type,
                controller=group_controller,
                action="edit",
                ckan_icon="edit",
            )
            map.connect(
                "%s_members" % group_type,
                "/%s/members/{id}" % group_type,
                controller=group_controller,
                action="members",
                ckan_icon="group",
            )
            map.connect(
                "%s_activity" % group_type,
                "/%s/activity/{id}/{offset}" % group_type,
                controller=group_controller,
                action="activity",
                ckan_icon="time",
            ),

            if 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

            if group_controller == "group":
                # Tell the default group controller that it is allowed to
                # handle other group_types.
                # Import it here to avoid circular imports.
                from ckan.controllers.group import GroupController

                GroupController.add_group_type(group_type)

    # Setup the fallback behaviour if one hasn't been defined.
    if _default_group_plugin is None:
        _default_group_plugin = DefaultGroupForm()
    if "group" not in _group_controllers:
        _group_controllers["group"] = "group"
    if "organization" not in _group_controllers:
        _group_controllers["organization"] = "organization"