diff --git a/interfaces.py b/interfaces.py
index 48f8019..f82aaee 100644
--- a/interfaces.py
+++ b/interfaces.py
@@ -108,6 +108,10 @@ class IConcept(IConceptSchema, ILoopsObject, IPotentialTarget):
""" Return a concept that provides the object's type.
"""
+ def getClients(relationships=None):
+ """ Return a sequence of objects that the concept is the target of.
+ """
+
def getChildren(predicates=None):
""" Return a sequence of concepts related to self as child concepts,
optionally restricted to the predicates given.
diff --git a/layout/base.py b/layout/base.py
index ebf6f76..a7c46f0 100644
--- a/layout/base.py
+++ b/layout/base.py
@@ -42,16 +42,19 @@ class LayoutNode(Node):
class NodeLayoutInstance(LayoutInstance):
+ @Lazy
+ def target(self):
+ return adapted(self.context.target)
+
@Lazy
def targetView(self):
request = self.view.request
- target = adapted(self.context.target)
- view = component.getMultiAdapter((target, request), name='layout')
+ view = component.getMultiAdapter((self.target, request), name='layout')
view.node = self.context
return view
-class NavigationNodeLayoutInstance(NodeLayoutInstance):
+class NavigationLayoutInstance(NodeLayoutInstance):
def getLayouts(self, region):
""" Return sublayout instances specified via subnodes of the current menu node.
@@ -70,3 +73,33 @@ class NavigationNodeLayoutInstance(NodeLayoutInstance):
li.template = layout
result.append(li)
return result
+
+
+class TargetLayoutInstance(NodeLayoutInstance):
+
+ def getLayouts(self, region):
+ """ Return sublayout instances specified by the target object.
+ """
+ target = self.target
+ if region is None or target is None:
+ return []
+ result = []
+ names = region.layouts.keys()
+ tp = target.context.conceptType
+ for n in tp.getClients():
+ if n.nodeType == 'info' and n.viewName in names:
+ layout = region.layouts[n.viewName]
+ li = component.getAdapter(n, ILayoutInstance,
+ name=layout.instanceName)
+ li.template = layout
+ result.append(li)
+ return result
+
+ @Lazy
+ def target(self):
+ viewAnnotations = self.view.request.annotations.get('loops.view', {})
+ target = viewAnnotations.get('target')
+ if target is None:
+ target = adapted(self.context.target)
+ return target
+
diff --git a/layout/configure.zcml b/layout/configure.zcml
index fca78db..48415a9 100644
--- a/layout/configure.zcml
+++ b/layout/configure.zcml
@@ -23,7 +23,12 @@
+ factory="loops.layout.base.NavigationLayoutInstance" />
+
+