本文整理汇总了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)
示例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", {})
示例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", {})
示例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'
示例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', {})
示例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)