Esempio n. 1
0
def register_path(app, model, path, variables, converters, required,
                  get_converters, model_factory, arguments=None):
    traject = app.traject

    converters = converters or {}
    if get_converters is not None:
        converters.update(get_converters())
    if arguments is None:
        arguments = get_arguments(model_factory, SPECIAL_ARGUMENTS)
    converters = app.argument_and_explicit_converters(arguments, converters)
    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,
                                         'extra_parameters' in arguments)
    if variables is None:
        variables = get_variables_func(arguments, app.mount_variables())

    traject.add_pattern(path, (model_factory, parameter_factory),
                        converters)

    inverse = Inverse(path, variables, converters, parameters.keys())
    app.register(generic.path, [model], inverse)
Esempio n. 2
0
def register_path(app, model, path, variables, converters, required,
                  model_factory, arguments=None):
    traject = app.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)