From 20bc06ed03142bd184cb2f7322bc229e8e4dc9fa Mon Sep 17 00:00:00 2001 From: Bert JW Regeer Date: Sun, 10 Apr 2016 22:15:38 -0600 Subject: Move event to the appropriate location This way the notification is not sent only after finding a route, but anytime generically before attempting traversal. --- pyramid/router.py | 16 +++++++++++++--- 1 file 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 -- cgit v1.2.3