target layout: also check individual object for sub-layouts, not only type
git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@3396 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
39533692d9
commit
fe193a538c
5 changed files with 94 additions and 10 deletions
46
layout/README.txt
Normal file
46
layout/README.txt
Normal file
|
@ -0,0 +1,46 @@
|
|||
===============================================================
|
||||
loops - Linked Objects for Organization and Processing Services
|
||||
===============================================================
|
||||
|
||||
Layout management.
|
||||
|
||||
($Id$)
|
||||
|
||||
|
||||
Setting up a loops Site and Utilities
|
||||
=====================================
|
||||
|
||||
Let's do some basic set up
|
||||
|
||||
>>> from zope import component, interface
|
||||
>>> from zope.traversing.api import getName
|
||||
>>> from zope.app.testing.setup import placefulSetUp, placefulTearDown
|
||||
>>> site = placefulSetUp(True)
|
||||
|
||||
and build a simple loops site with a concept manager and some concepts
|
||||
(with a relation registry, a catalog, and all the type machinery - what
|
||||
in real life is done via standard ZCML setup or via local utility
|
||||
configuration):
|
||||
|
||||
>>> from loops.integrator.testsetup import TestSite
|
||||
>>> t = TestSite(site)
|
||||
>>> concepts, resources, views = t.setup()
|
||||
>>> loopsRoot = concepts.getLoopsRoot()
|
||||
|
||||
>>> from loops.layout.tests import setup
|
||||
>>> setup()
|
||||
|
||||
|
||||
Defining Layouts
|
||||
================
|
||||
|
||||
>>> from loops.layout.base import LayoutNode
|
||||
|
||||
>>> demo = views['demo'] = LayoutNode('Demo Root Layout')
|
||||
>>> demo.nodeType = 'menu'
|
||||
|
||||
|
||||
Fin de partie
|
||||
=============
|
||||
|
||||
>>> placefulTearDown()
|
|
@ -23,6 +23,7 @@ $Id$
|
|||
"""
|
||||
|
||||
from zope import component
|
||||
from zope.component import adapts
|
||||
from zope.cachedescriptors.property import Lazy
|
||||
from zope.interface import implements
|
||||
|
||||
|
@ -44,6 +45,8 @@ class LayoutNode(Node):
|
|||
|
||||
class NodeLayoutInstance(LayoutInstance):
|
||||
|
||||
adapts(ILayoutNode)
|
||||
|
||||
@Lazy
|
||||
def viewAnnotations(self):
|
||||
return self.view.request.annotations.get('loops.view', {})
|
||||
|
@ -62,6 +65,8 @@ class NodeLayoutInstance(LayoutInstance):
|
|||
|
||||
class SubnodesLayoutInstance(NodeLayoutInstance):
|
||||
|
||||
adapts(ILayoutNode)
|
||||
|
||||
def getLayouts(self, region):
|
||||
""" Return sublayout instances specified via subnodes of the current menu node.
|
||||
"""
|
||||
|
@ -82,19 +87,24 @@ class SubnodesLayoutInstance(NodeLayoutInstance):
|
|||
|
||||
|
||||
class TargetLayoutInstance(NodeLayoutInstance):
|
||||
""" Associates a layout with all objects of a certain type.
|
||||
"""
|
||||
|
||||
adapts(ILayoutNode)
|
||||
|
||||
def getLayouts(self, region):
|
||||
""" Return sublayout instances specified by the target object.
|
||||
"""
|
||||
target = self.target
|
||||
if region is None or target is None:
|
||||
if region is None or self.target is None:
|
||||
return []
|
||||
#result = []
|
||||
result = super(TargetLayoutInstance, self).getLayouts(region)
|
||||
names = region.layouts.keys()
|
||||
tp = target.context.getType()
|
||||
pageName = self.viewAnnotations.get('pageName', u'')
|
||||
for n in tp.getClients():
|
||||
obj = self.target.context
|
||||
tp = obj.getType()
|
||||
for n in obj.getClients() + tp.getClients():
|
||||
if not ILayoutNode.providedBy(n):
|
||||
continue
|
||||
if n.nodeType == 'info' and n.viewName in names:
|
||||
if pageName != n.pageName:
|
||||
continue
|
||||
|
@ -113,4 +123,3 @@ class TargetLayoutInstance(NodeLayoutInstance):
|
|||
if target is None:
|
||||
target = adapted(self.context.target)
|
||||
return target
|
||||
|
||||
|
|
|
@ -42,7 +42,8 @@ class ConceptView(BaseView):
|
|||
def children(self):
|
||||
for c in self.context.getChildren():
|
||||
a = adapted(c)
|
||||
view = component.getMultiAdapter((c, self.request), name='layout')
|
||||
#view = component.getMultiAdapter((c, self.request), name='layout')
|
||||
view = component.getMultiAdapter((a, self.request), name='layout')
|
||||
view.node = self.node
|
||||
yield view
|
||||
|
||||
|
|
|
@ -17,16 +17,13 @@
|
|||
</zope:class>
|
||||
|
||||
<zope:adapter
|
||||
for="loops.layout.interfaces.ILayoutNode"
|
||||
factory="loops.layout.base.NodeLayoutInstance" />
|
||||
|
||||
<zope:adapter
|
||||
for="loops.layout.interfaces.ILayoutNode"
|
||||
name="subnodes"
|
||||
factory="loops.layout.base.SubnodesLayoutInstance" />
|
||||
|
||||
<zope:adapter
|
||||
for="loops.layout.interfaces.ILayoutNode"
|
||||
name="target"
|
||||
factory="loops.layout.base.TargetLayoutInstance" />
|
||||
|
||||
|
|
31
layout/tests.py
Executable file
31
layout/tests.py
Executable file
|
@ -0,0 +1,31 @@
|
|||
# $Id$
|
||||
|
||||
import unittest, doctest
|
||||
from zope.testing.doctestunit import DocFileSuite
|
||||
|
||||
from zope import component
|
||||
from loops.layout.base import NodeLayoutInstance, SubnodesLayoutInstance
|
||||
from loops.layout.base import TargetLayoutInstance
|
||||
|
||||
def setup():
|
||||
component.provideAdapter(NodeLayoutInstance)
|
||||
component.provideAdapter(SubnodesLayoutInstance, name='subnodes')
|
||||
component.provideAdapter(TargetLayoutInstance, name='target')
|
||||
|
||||
|
||||
class Test(unittest.TestCase):
|
||||
"Basic tests for the layout sub-package."
|
||||
|
||||
def testSomething(self):
|
||||
pass
|
||||
|
||||
|
||||
def test_suite():
|
||||
flags = doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS
|
||||
return unittest.TestSuite((
|
||||
unittest.makeSuite(Test),
|
||||
DocFileSuite('README.txt', optionflags=flags),
|
||||
))
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main(defaultTest='test_suite')
|
Loading…
Add table
Reference in a new issue