예제 #1
0
파일: menu.py 프로젝트: imfht/flaskapps
def build_menu_structure(menu_id, active_item=None, **kwargs):
    """Build a menu (list of entries) with sections/items.

    Information is provided by specific signals and filtered
    by menu id.
    This can be used as a very thin framework for menu
    handling across the app.

    :param menu_id: menu_id used to filter out signal calls
    :param active_item: ID of currently active menu item
    :param kwargs: extra arguments passed to the signals
    :return: properly sorted list (taking weights into account)
    """
    top_level = set()
    sections = {}

    for id_, section in named_objects_from_signal(
            signals.menu.sections.send(menu_id, **kwargs)).items():
        sections[id_] = section
        top_level.add(section)

    for id_, item in named_objects_from_signal(
            signals.menu.items.send(menu_id, **kwargs)).items():
        if id_ == active_item:
            item.active = True
        if item.section is None:
            top_level.add(item)
        else:
            sections[item.section].add_item(item)

    return sorted(top_level, key=lambda x: (-x.weight, x.title))
예제 #2
0
파일: menu.py 프로젝트: bkolobara/indico
def build_menu_structure(menu_id, active_item=None, **kwargs):
    """Build a menu (list of entries) with sections/items.

    Information is provided by specific signals and filtered
    by menu id.
    This can be used as a very thin framework for menu
    handling across the app.

    :param menu_id: menu_id used to filter out signal calls
    :param active_item: ID of currently active menu item
    :param kwargs: extra arguments passed to the signals
    :return: properly sorted list (taking weights into account)
    """
    top_level = set()
    sections = {}

    for id_, section in named_objects_from_signal(signals.menu.sections.send(menu_id, **kwargs)).iteritems():
        sections[id_] = section
        top_level.add(section)

    for id_, item in named_objects_from_signal(signals.menu.items.send(menu_id, **kwargs)).iteritems():
        if id_ == active_item:
            item.active = True
        if item.section is None:
            top_level.add(item)
        else:
            sections[item.section].add_item(item)

    return sorted(top_level, key=lambda x: (-x.weight, x.title))
예제 #3
0
def test_named_objects_from_signal_duplicate():
    objects = [
        type('Dummy', (object, ), {'name': name})
        for name in ('a', 'a', 'b', 'c', 'c')
    ]
    signal_response = _make_signal_response(objects)
    with pytest.raises(RuntimeError) as exc_info:
        named_objects_from_signal(signal_response)
    assert str(exc_info.value) == 'Non-unique object names: a, c'
예제 #4
0
def get_field_definitions(for_):
    """Gets a dict containing all field definitions

    :param for_: The identifier/object passed to the `get_fields`
                 signal to identify which fields to get.
    """
    return named_objects_from_signal(signals.get_fields.send(for_), plugin_attr='plugin')
예제 #5
0
def get_field_definitions(for_):
    """Get a dict containing all field definitions.

    :param for_: The identifier/object passed to the `get_fields`
                 signal to identify which fields to get.
    """
    return named_objects_from_signal(signals.get_fields.send(for_), plugin_attr='plugin')
예제 #6
0
파일: rules.py 프로젝트: indico/indico
def get_conditions(context, **kwargs):
    """Get a dict of available conditions.

    :param context: the context where the conditions are used
    :param kwargs: arguments specific to the context
    """
    return named_objects_from_signal(signals.get_conditions.send(context, **kwargs))
예제 #7
0
def get_conditions(context, **kwargs):
    """Get a dict of available conditions.

    :param context: the context where the conditions are used
    :param kwargs: arguments specific to the context
    """
    return named_objects_from_signal(signals.core.get_conditions.send(context, **kwargs))
예제 #8
0
def test_named_objects_from_signal_plugin_attr():
    objects = [type('Dummy', (object,), {'name': name}) for name in ('a', 'b')]
    signal_response = _make_signal_response(objects)
    signal_response[-1] = (MagicMock(indico_plugin='foo'), signal_response[-1][1])
    rv = named_objects_from_signal(signal_response, plugin_attr='plugin')
    assert rv == {'a': objects[0], 'b': objects[1]}
    assert rv['a'].plugin is None
    assert rv['b'].plugin == 'foo'
예제 #9
0
def test_named_objects_from_signal_plugin_attr():
    objects = [type('Dummy', (object,), {'name': name}) for name in ('a', 'b')]
    signal_response = _make_signal_response(objects)
    signal_response[-1] = (MagicMock(indico_plugin='foo'), signal_response[-1][1])
    rv = named_objects_from_signal(signal_response, plugin_attr='plugin')
    assert rv == {'a': objects[0], 'b': objects[1]}
    assert rv['a'].plugin is None
    assert rv['b'].plugin == 'foo'
예제 #10
0
파일: cloning.py 프로젝트: qroques/indico
def get_event_cloners():
    """Get the dict containing all available event cloners.

    The returned dict is ordered based on the dependencies of each
    cloner and when executing the cloners MUST be executed in that
    order.
    """
    cloners = named_objects_from_signal(signals.event_management.get_cloners.send(), plugin_attr='plugin')
    return OrderedDict(_resolve_dependencies(cloners))
예제 #11
0
def test_named_objects_from_signal(name_attr):
    objects = [
        type('Dummy', (object, ), {name_attr: name}) for name in ('a', 'b')
    ]
    signal_response = _make_signal_response(objects)
    assert named_objects_from_signal(signal_response, name_attr=name_attr) == {
        'a': objects[0],
        'b': objects[1]
    }
예제 #12
0
파일: menu.py 프로젝트: innovexa/IDC-Events
def get_menu_item(menu_id, item, **kwargs):
    """Get a specific menu item.

    :param menu_id: menu_id used to filter out signal calls
    :param item: ID of the item to retrieve
    :param kwargs: extra arguments passed to the signals
    :return: the specified menu item or ``None``
    """
    return named_objects_from_signal(signals.menu.items.send(menu_id, **kwargs)).get(item)
예제 #13
0
def get_event_cloners():
    """Get the dict containing all available event cloners.

    The returned dict is ordered based on the dependencies of each
    cloner and when executing the cloners MUST be executed in that
    order.
    """
    cloners = named_objects_from_signal(signals.event_management.get_cloners.send(), plugin_attr='plugin')
    return OrderedDict(_resolve_dependencies(cloners))
예제 #14
0
 def _process(self):
     menu_entries = named_objects_from_signal(
         signals.menu.items.send('event-editing-sidemenu',
                                 event=self.event))
     is_editing_manager = self.event.can_manage(
         session.user, permission='editing_manager')
     show_editable_list = {
         et.name:
         (is_editing_manager
          or self.event.can_manage(session.user, et.editor_permission))
         for et in EditableType
     }
     return jsonify(items=EditingMenuItemSchema(many=True).dump(
         list(menu_entries.values())),
                    show_management_link=is_editing_manager,
                    show_editable_list=show_editable_list)
예제 #15
0
파일: util.py 프로젝트: bkolobara/indico
 def _get_indico_plugin_commands(self, ctx):
     if self._indico_plugin_commands is not None:
         return self._indico_plugin_commands
     try:
         from indico.core import signals
         from indico.util.signals import named_objects_from_signal
         ctx.ensure_object(ScriptInfo).load_app()
         cmds = named_objects_from_signal(signals.plugin.cli.send(), plugin_attr='_indico_plugin')
         rv = {}
         for name, cmd in cmds.viewitems():
             if cmd._indico_plugin:
                 self._wrap_in_plugin_context(cmd._indico_plugin, cmd)
             rv[name] = cmd
     except Exception as exc:
         if 'No indico config found' not in unicode(exc):
             click.echo(click.style('Loading plugin commands failed:', fg='red', bold=True))
             click.echo(click.style(traceback.format_exc(), fg='red'))
         rv = {}
     self._indico_plugin_commands = rv
     return rv
예제 #16
0
 def _get_indico_plugin_commands(self, ctx):
     if self._indico_plugin_commands is not None:
         return self._indico_plugin_commands
     try:
         from indico.core import signals
         from indico.util.signals import named_objects_from_signal
         ctx.ensure_object(ScriptInfo).load_app()
         cmds = named_objects_from_signal(signals.plugin.cli.send(), plugin_attr='_indico_plugin')
         rv = {}
         for name, cmd in cmds.items():
             if cmd._indico_plugin:
                 self._wrap_in_plugin_context(cmd._indico_plugin, cmd)
             rv[name] = cmd
     except Exception as exc:
         if 'No indico config found' not in str(exc):
             click.echo(click.style('Loading plugin commands failed:', fg='red', bold=True))
             click.echo(click.style(traceback.format_exc(), fg='red'))
         rv = {}
     self._indico_plugin_commands = rv
     return rv
예제 #17
0
def get_field_types():
    """Gets a dict containing all field types"""
    return named_objects_from_signal(signals.event.get_survey_fields.send(), plugin_attr='plugin')
예제 #18
0
def get_available_permissions(type_):
    """Get a dict containing all permissions for a given object type."""
    return named_objects_from_signal(
        signals.acl.get_management_permissions.send(type_))
예제 #19
0
def get_request_definitions():
    """Return a dict of request definitions."""
    return named_objects_from_signal(
        signals.plugin.get_event_request_definitions.send(),
        plugin_attr='plugin')
예제 #20
0
파일: util.py 프로젝트: wtakase/indico
def get_agreement_definitions():
    return named_objects_from_signal(signals.agreements.get_definitions.send(),
                                     plugin_attr='plugin')
예제 #21
0
파일: util.py 프로젝트: imfht/flaskapps
def get_menu_entries_from_signal():
    return named_objects_from_signal(signals.event.sidemenu.send(), plugin_attr='plugin')
예제 #22
0
파일: roles.py 프로젝트: florv/indico
def get_available_roles(type_):
    """Gets a dict containing all roles for a given object type"""
    return named_objects_from_signal(signals.acl.get_management_roles.send(type_))
예제 #23
0
파일: util.py 프로젝트: timgates42/indico
def get_log_renderers():
    return named_objects_from_signal(signals.event.get_log_renderers.send(),
                                     plugin_attr='plugin')
예제 #24
0
 def _process(self):
     menu_entries = named_objects_from_signal(
         signals.menu.items.send('event-editing-sidemenu',
                                 event=self.event))
     return EditingMenuItemSchema(many=True).jsonify(menu_entries.values())
예제 #25
0
파일: util.py 프로젝트: bkolobara/indico
def get_request_definitions():
    """Returns a dict of request definitions"""
    return named_objects_from_signal(signals.plugin.get_event_request_definitions.send(), plugin_attr='plugin')
예제 #26
0
파일: util.py 프로젝트: jacquesd/indico
def get_log_renderers():
    return named_objects_from_signal(signals.event.get_log_renderers.send(), plugin_attr='plugin')
예제 #27
0
def get_storage_backends():
    return named_objects_from_signal(signals.core.get_storage_backends.send(),
                                     plugin_attr='plugin')
예제 #28
0
def _get_placeholders(context, **kwargs):
    return named_objects_from_signal(
        signals.get_placeholders.send(context, **kwargs))
예제 #29
0
def get_placeholders(context, **kwargs):
    return named_objects_from_signal(signals.get_placeholders.send(context, **kwargs))
예제 #30
0
def get_available_roles(type_):
    """Gets a dict containing all roles for a given object type"""
    return named_objects_from_signal(signals.acl.get_management_roles.send(type_))
예제 #31
0
파일: util.py 프로젝트: DirkHoffmann/indico
def get_agreement_definitions():
    return named_objects_from_signal(signals.agreements.get_definitions.send(), plugin_attr='plugin')
예제 #32
0
파일: util.py 프로젝트: innovexa/IDC-Events
def get_feature_definitions():
    """Gets a dict containing all feature definitions"""
    return named_objects_from_signal(
        signals.event.get_feature_definitions.send(), plugin_attr='plugin')
예제 #33
0
def test_named_objects_from_signal(name_attr):
    objects = [type('Dummy', (object,), {name_attr: name}) for name in ('a', 'b')]
    signal_response = _make_signal_response(objects)
    assert named_objects_from_signal(signal_response, name_attr=name_attr) == {'a': objects[0], 'b': objects[1]}
예제 #34
0
파일: util.py 프로젝트: jacquesd/indico
def get_feature_definitions():
    """Gets a dict containing all feature definitions"""
    return named_objects_from_signal(signals.event.get_feature_definitions.send(), plugin_attr='plugin')
예제 #35
0
def test_named_objects_from_signal_duplicate():
    objects = [type('Dummy', (object,), {'name': name}) for name in ('a', 'a', 'b', 'c', 'c')]
    signal_response = _make_signal_response(objects)
    with pytest.raises(RuntimeError) as exc_info:
        named_objects_from_signal(signal_response)
    assert str(exc_info.value) == 'Non-unique object names: a, c'
예제 #36
0
파일: util.py 프로젝트: OmeGak/indico
def get_menu_entries_from_signal():
    return named_objects_from_signal(signals.event.sidemenu.send(), plugin_attr='plugin')
예제 #37
0
파일: backend.py 프로젝트: bkolobara/indico
def get_storage_backends():
    return named_objects_from_signal(signals.get_storage_backends.send(), plugin_attr='plugin')