Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

route_url() and pregenerator #473

Open
jenstroeger opened this issue Mar 1, 2018 · 1 comment
Open

route_url() and pregenerator #473

jenstroeger opened this issue Mar 1, 2018 · 1 comment
Labels

Comments

@jenstroeger
Copy link
Collaborator

I noticed that Pyramid allows to pass a pregenerator to request.add_route(), which is then used by request.route_url() to touch up its arguments.

I don’t see this parameter for Service() though. What’s the recommended way of adding such a pregenerator?

@leplatrem
Copy link
Contributor

It doesn't seem to be possible to pass custom route arguments currently.

But we could add a service attribute (like predicate) here for example:

# 1. register route
route_args = {}
if hasattr(service, 'factory'):
route_args['factory'] = service.factory
routes = config.get_predlist('route')
for predicate in routes.sorter.names:
# Do not let the custom predicates handle validation of Header Accept,
# which will pass it through to pyramid. It is handled by
# _fallback_view(), because it allows callable.
if predicate == 'accept':
continue
if hasattr(service, predicate):
route_args[predicate] = getattr(service, predicate)
config.add_route(route_name, service.path, **route_args)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants