diff options
| author | Bert JW Regeer <bertjw@regeer.org> | 2016-04-10 22:15:38 -0600 |
|---|---|---|
| committer | Bert JW Regeer <bertjw@regeer.org> | 2016-04-10 22:15:38 -0600 |
| commit | 20bc06ed03142bd184cb2f7322bc229e8e4dc9fa (patch) | |
| tree | 5db0e07fc6d70ef626c9af90a16bcb3ef6d5fd32 | |
| parent | 732d80b476ccc883fc7b6209a4256ef97946e1eb (diff) | |
| download | pyramid-20bc06ed03142bd184cb2f7322bc229e8e4dc9fa.tar.gz pyramid-20bc06ed03142bd184cb2f7322bc229e8e4dc9fa.tar.bz2 pyramid-20bc06ed03142bd184cb2f7322bc229e8e4dc9fa.zip | |
Move event to the appropriate location
This way the notification is not sent only after finding a route, but
anytime generically before attempting traversal.
| -rw-r--r-- | pyramid/router.py | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/pyramid/router.py b/pyramid/router.py index 99ea6ffa5..19773cf62 100644 --- a/pyramid/router.py +++ b/pyramid/router.py @@ -113,14 +113,21 @@ class Router(object): name=route.name, default=IRequest) - has_listeners and notify(BeforeTraversal(request)) - root_factory = route.factory or self.root_factory + # Notify anyone listening that we are about to start traversal + # + # Notify before creating root_factory in case we want to do something + # special on a route we may have matched. See + # https://github.com/Pylons/pyramid/pull/1876 for ideas of what is + # possible. + has_listeners and notify(BeforeTraversal(request)) + + # Create the root factory root = root_factory(request) attrs['root'] = root - # find a context + # We are about to traverse and find a context traverser = adapters.queryAdapter(root, ITraverser) if traverser is None: traverser = ResourceTreeTraverser(root) @@ -136,6 +143,9 @@ class Router(object): ) attrs.update(tdict) + + # Notify anyone listening that we have a context and traversal is + # complete has_listeners and notify(ContextFound(request)) # find a view callable |
