Updated traverser to notify BeforeTraverseEvent on last traversed object
authorThierry Florac <thierry.florac@onf.fr>
Wed, 30 May 2018 14:55:51 +0200
changeset 187 fe50c0414855
parent 186 c08b45bbed38
child 188 bed6978c453c
child 261 a11273a42e18
Updated traverser to notify BeforeTraverseEvent on last traversed object
src/pyams_utils/traversing.py
--- a/src/pyams_utils/traversing.py	Mon May 28 14:07:10 2018 +0200
+++ b/src/pyams_utils/traversing.py	Wed May 30 14:55:51 2018 +0200
@@ -111,6 +111,7 @@
                     request.registry.notify(BeforeTraverseEvent(ob, request))
 
                 if segment[:2] == view_selector:
+                    # check for view name prefixed by '@@'
                     return {'context': ob,
                             'view_name': segment[2:],
                             'subpath': vpath_tuple[i + 1:],
@@ -119,7 +120,12 @@
                             'virtual_root_path': vroot_tuple,
                             'root': root}
 
-                if segment[:2] == ns_selector:
+                elif segment[:2] == ns_selector:
+                    # check for namespace prefixed by '++'
+                    # when a namespace is detected, named "ITraversable" multi-adapters are searched for
+                    # context and request, for context and for request, sequentially; a NotFound exception is
+                    # raised if traverser can't be found, otherwise it's "traverse" method is called to get new
+                    # context
                     ns, name = segment[2:].split(ns_selector, 1)
                     registry = get_current_registry()
                     traverser = registry.queryMultiAdapter((ob, request), ITraversable, ns)
@@ -159,6 +165,9 @@
                 ob = next
                 i += 1
 
+        if ob is not root:
+            request.registry.notify(BeforeTraverseEvent(ob, request))
+
         return {'context': ob,
                 'view_name': empty,
                 'subpath': subpath,