Exemplo n.º 1
0
def register_resource(config, name, model, interface, with_index=False):
    # in case of tests, this method may be called multiple times!
    if [rsc for rsc in RESOURCES if rsc.name == name]:
        return
    RESOURCES.append(Resource(name, model, interface, with_index=with_index))
    config.register_adapter(excel.ExcelAdapter, interface)
    config.add_route_and_view(name,
                              '/%ss/{id:[^/\.]+}' % name,
                              resource_view,
                              factory=partial(ctx_factory, model, 'rsc'))
    if with_index:
        config.add_route_and_view(name + 's',
                                  '/%ss' % name,
                                  index_view,
                                  factory=partial(ctx_factory, model, 'index'))
Exemplo n.º 2
0
Arquivo: app.py Projeto: mitcho/clld
def register_resource(config, name, model, interface, with_index=False):
    # in case of tests, this method may be called multiple times!
    if [rsc for rsc in RESOURCES if rsc.name == name]:
        return
    RESOURCES.append(Resource(name, model, interface, with_index=with_index))
    config.register_adapter(excel.ExcelAdapter, interface)
    config.add_route_and_view(
        name,
        '/%ss/{id:[^/\.]+}' % name,
        resource_view,
        factory=partial(ctx_factory, model, 'rsc'))
    if with_index:
        config.add_route_and_view(
            name + 's',
            '/%ss' % name,
            index_view,
            factory=partial(ctx_factory, model, 'index'))
Exemplo n.º 3
0
def register_resource(config, name, model, interface, with_index=False, **kw):
    """Directive to register custom resources.

    .. note::

        The directive accepts arbitrary keyword arguments for backwards compatibility.
    """
    # in case of tests, this method may be called multiple times!
    if [rsc for rsc in RESOURCES if rsc.name == name]:
        return
    rsc = Resource(name, model, interface, with_index=with_index)
    RESOURCES.append(rsc)
    config.register_resource_routes_and_views(rsc)

    if not config.registry.queryUtility(interfaces.IDataTable, name=rsc.plural):
        config.register_datatable(
            rsc.plural, getattr(datatables, rsc.plural.capitalize(), DataTable))

    register_resource_adapters(config, rsc)
Exemplo n.º 4
0
def register_resource(config, name, model, interface, with_index=False, **kw):
    """Directive to register custom resources.

    .. note::

        The directive accepts arbitrary keyword arguments for backwards compatibility.
    """
    # in case of tests, this method may be called multiple times!
    if [rsc for rsc in RESOURCES if rsc.name == name]:
        return
    rsc = Resource(name, model, interface, with_index=with_index)
    RESOURCES.append(rsc)
    config.register_resource_routes_and_views(rsc)

    if not config.registry.queryUtility(interfaces.IDataTable, name=rsc.plural):
        config.register_datatable(
            rsc.plural, getattr(datatables, rsc.plural.capitalize(), DataTable))

    register_resource_adapters(config, rsc)