当前位置: 首页>>代码示例>>Python>>正文


Python Traject.inverse方法代码示例

本文整理汇总了Python中morepath.traject.Traject.inverse方法的典型用法代码示例。如果您正苦于以下问题:Python Traject.inverse方法的具体用法?Python Traject.inverse怎么用?Python Traject.inverse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在morepath.traject.Traject的用法示例。


在下文中一共展示了Traject.inverse方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: register_path

# 需要导入模块: from morepath.traject import Traject [as 别名]
# 或者: from morepath.traject.Traject import inverse [as 别名]
def register_path(app, model, path, variables, converters, required,
                  model_factory, arguments=None):
    traject = app.traject
    if traject is None:
        traject = Traject()
        app.traject = traject

    converters = converters or {}
    if arguments is None:
        arguments = get_arguments(model_factory, SPECIAL_ARGUMENTS)
    converters = get_converters(arguments, converters,
                                app.converter_for_type, app.converter_for_value)
    exclude = Path(path).variables()
    exclude.update(app.mount_variables())
    parameters = get_url_parameters(arguments, exclude)
    if required is None:
        required = set()
    required = set(required)
    parameter_factory = ParameterFactory(parameters, converters, required)

    if variables is None:
        variables = get_variables_func(arguments, app.mount_variables())

    traject.add_pattern(path, (model_factory, parameter_factory),
                        converters)
    traject.inverse(model, path, variables, converters, list(parameters.keys()))


    def get_app(model):
        return app

    app.register(generic.app, [model], get_app)
开发者ID:iapilgrim,项目名称:morepath,代码行数:34,代码来源:path.py

示例2: test_path_for_model_with_converter

# 需要导入模块: from morepath.traject import Traject [as 别名]
# 或者: from morepath.traject.Traject import inverse [as 别名]
def test_path_for_model_with_converter():
    traject = Traject()

    class IdModel(object):
        def __init__(self, id):
            self.id = id

    traject.inverse(IdModel, "foo/{id}", lambda model: {"id": model.id}, dict(id=Converter(int)), [])
    assert traject.path(IdModel(1)) == ("foo/1", {})
开发者ID:reinout,项目名称:morepath,代码行数:11,代码来源:test_traject.py

示例3: test_path_for_model

# 需要导入模块: from morepath.traject import Traject [as 别名]
# 或者: from morepath.traject.Traject import inverse [as 别名]
def test_path_for_model():
    traject = Traject()

    class IdModel(object):
        def __init__(self, id):
            self.id = id

    traject.inverse(IdModel, "foo/{id}", lambda model: {"id": model.id}, {}, [])
    assert traject.path(IdModel("a")) == ("foo/a", {})
开发者ID:reinout,项目名称:morepath,代码行数:11,代码来源:test_traject.py

示例4: test_path_for_model_with_converter

# 需要导入模块: from morepath.traject import Traject [as 别名]
# 或者: from morepath.traject.Traject import inverse [as 别名]
def test_path_for_model_with_converter():
    traject = Traject()

    class IdModel(object):
        def __init__(self, id):
            self.id = id

    traject.inverse(IdModel, 'foo/{id:int}',
                    lambda model: {'id': model.id})
    assert traject.path(IdModel(1)) == 'foo/1'
开发者ID:kod3r,项目名称:morepath,代码行数:12,代码来源:test_traject.py

示例5: test_path_for_model

# 需要导入模块: from morepath.traject import Traject [as 别名]
# 或者: from morepath.traject.Traject import inverse [as 别名]
def test_path_for_model():
    traject = Traject()

    class IdModel(object):
        def __init__(self, id):
            self.id = id

    traject.inverse(IdModel, 'foo/{id}',
                    lambda model: {'id': model.id},
                    {}, [])
    assert traject.path(IdModel('a')) == ('foo/a', {})
开发者ID:iapilgrim,项目名称:morepath,代码行数:13,代码来源:test_traject.py

示例6: register_model

# 需要导入模块: from morepath.traject import Traject [as 别名]
# 或者: from morepath.traject.Traject import inverse [as 别名]
def register_model(app, model, path, variables, model_factory,
                   base=None, get_base=None):
    if base is not None:
        traject = app.exact(generic.traject, [base])
        if traject is None:
            traject = Traject()
            app.register(generic.traject, [base], lambda base: traject)
    else:
        traject = app.traject
        if traject is None:
            traject = Traject()
            app.traject = traject
    traject.add_pattern(path, model_factory)
    traject.inverse(model, path, variables)

    if get_base is None:
        def get_base(model):
            return app

    app.register(generic.base, [model], get_base)
开发者ID:kod3r,项目名称:morepath,代码行数:22,代码来源:model.py


注:本文中的morepath.traject.Traject.inverse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。