[Checkins] SVN: grokcore.resource/trunk/src/grokcore/resource/event.py Use private API in grokcore.layout 1.6 to get to the layout.

Jan-Jaap Driessen cvs-admin at zope.org
Sun May 13 19:36:24 UTC 2012


Log message for revision 125855:
  Use private API in grokcore.layout 1.6 to get to the layout.

Changed:
  U   grokcore.resource/trunk/src/grokcore/resource/event.py

-=-
Modified: grokcore.resource/trunk/src/grokcore/resource/event.py
===================================================================
--- grokcore.resource/trunk/src/grokcore/resource/event.py	2012-05-13 19:35:40 UTC (rev 125854)
+++ grokcore.resource/trunk/src/grokcore/resource/event.py	2012-05-13 19:36:21 UTC (rev 125855)
@@ -1,5 +1,8 @@
+import zope.component
 import zope.app.publication.interfaces
 import grokcore.component
+import grokcore.layout
+import grokcore.layout.components
 import zope.security.proxy
 import zope.contentprovider.interfaces
 
@@ -8,17 +11,29 @@
 @grokcore.component.subscribe(
     grokcore.resource.interfaces.IResourcesIncluder,
     zope.app.publication.interfaces.IBeforeTraverseEvent)
-def handle_inclusion(includer, event):
+def handle_resources(includer, event):
     includer = zope.security.proxy.removeSecurityProxy(includer)
-    for resources in grokcore.resource.directives.include.bind().get(includer):
+    for resources in grokcore.resource.directives.resources.bind().get(includer):
         for resource in resources:
             resource.need()
 
+    # In case of a grokcore.layout.components.LayoutAware object,
+    # the layout attribute is a Layout object that also can have resources.
+    if not isinstance(includer, grokcore.layout.components.LayoutAware):
+        return
+    # Using an implementation detail of LayoutAware here.
+    layout = includer._get_layout()
+    if grokcore.resource.interfaces.IResourcesIncluder.providedBy(layout):
+        for resources in grokcore.resource.directives.resources.bind().get(
+                layout):
+            for resource in resources:
+                resource.need()
+
 @grokcore.component.subscribe(
     grokcore.resource.interfaces.IResourcesIncluder,
     zope.contentprovider.interfaces.IBeforeUpdateEvent)
 def handle_inclusion(includer, event):
     includer = zope.security.proxy.removeSecurityProxy(includer)
-    for resources in grokcore.resource.directives.include.bind().get(includer):
+    for resources in grokcore.resource.directives.resources.bind().get(includer):
         for resource in resources:
             resource.need()



More information about the checkins mailing list