work in progress: layout management

git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@2910 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
helmutm 2008-10-08 20:28:30 +00:00
parent 9af3d9ab29
commit 96043fb340
5 changed files with 90 additions and 23 deletions

4
external/base.py vendored
View file

@ -195,11 +195,9 @@ class Extractor(Base):
#data = instance.applyTemplate(mode='export')
data = instance.applyTemplate(mode='edit')
noexp = getattr(aObj, '_noexportAttributes', ())
for attr in noexp:
for attr in tuple(noexp) + ('title', 'name'):
if attr in data:
del data[attr]
if 'title' in data:
del data['title']
data['description'] = obj.description
if not data['description']:
del data['description']

View file

@ -427,6 +427,19 @@ class IBaseNode(IOrderedContainer):
""" Return the loops root object.
"""
def getParentNode(nodeTypes=None):
""" Return the next node up the node hierarchy. If the nodeTypes
parameter is given, search for the next node that has one of
the types in the nodeTypes list.
Return None if no suitable node can be found.
"""
def getChildNodes(nodeTypes=None):
""" Return a sequence of nodes contained in this node. If the
nodeTypes parameter is given return only nodes of these types.
"""
class INodeSchema(IView):
@ -456,19 +469,6 @@ class INode(INodeSchema, IBaseNode):
"""
contains(IView)
def getParentNode(nodeTypes=None):
""" Return the next node up the node hierarchy. If the nodeTypes
parameter is given, search for the next node that has one of
the types in the nodeTypes list.
Return None if no suitable node can be found.
"""
def getChildNodes(nodeTypes=None):
""" Return a sequence of nodes contained in this node. If the
nodeTypes parameter is given return only nodes of these types.
"""
def getMenu():
""" Return the menu node this node belongs to or None if not found.
"""
@ -501,7 +501,8 @@ class INodeAdapter(Interface):
"""
class IViewManager(ILoopsObject, IBaseNode):
#class IViewManager(ILoopsObject, IBaseNode):
class IViewManager(ILoopsObject, IOrderedContainer):
""" A manager/container for views.
"""
contains(IView)

View file

@ -22,9 +22,12 @@ Layout node + instance implementations.
$Id$
"""
from zope.cachedescriptors.property import Lazy
from zope.interface import implements
from cybertools.composer.layout.base import LayoutInstance
from cybertools.composer.layout.base import Layout, LayoutInstance
from cybertools.composer.layout.interfaces import ILayoutInstance
from loops.layout.browser import ConceptView
from loops.layout.interfaces import ILayoutNode, ILayoutNodeContained
from loops.view import Node
@ -34,6 +37,38 @@ class LayoutNode(Node):
implements(ILayoutNode, ILayoutNodeContained)
# layout instances
class NodeLayoutInstance(LayoutInstance):
pass
def getLayouts(self, region):
""" Return sublayout instances.
"""
if region is None:
return []
result = []
sublayouts = self.template.sublayouts
if sublayouts is not None: # hard-coded sublayouts
for l in region.layouts:
if sublayouts is None or l.name in sublayouts:
li = ILayoutInstance(self.context)
li.template = l
result.append(li)
return result
# sublayouts specified via subnodes
subnodes = self.context.values()
names = region.layouts.keys()
for n in subnodes:
if n.viewName in names:
layout = region.layouts[n.viewName]
li = ILayoutInstance(n)
li.template = layout
result.append(li)
# if not result: get layouts from parent node(s)
return result
@Lazy
def targetView(self):
request = self.view.request
return ConceptView(self.context.target, request, self.context)

View file

@ -23,8 +23,10 @@ $Id$
"""
from zope.cachedescriptors.property import Lazy
from zope.traversing.browser import absoluteURL
from cybertools.composer.layout.browser.view import Page
from loops.browser.common import BaseView
class LayoutNodeView(Page):
@ -32,3 +34,36 @@ class LayoutNodeView(Page):
@Lazy
def layoutName(self):
return self.context.viewName or 'page'
@Lazy
def layoutNames(self):
result = []
n = self.context
while n is not None:
if n.viewName:
result.append(n.viewName)
n = n.getParentNode()
result.append('page')
return result
class ConceptView(object):
def __init__(self, context, request, node=None):
self.context = context
self.request = request
self.node = node
@Lazy
def title(self):
return self.context.title
@Lazy
def url(self):
return absoluteURL(self.node, self.request)
@property
def children(self):
for c in self.context.getChildren():
yield ConceptView(c, self.request, self.node)

View file

@ -26,8 +26,7 @@
name="index.html"
for="loops.layout.interfaces.ILayoutNode"
class="loops.layout.browser.LayoutNodeView"
permission="zope.View"
/>
permission="zope.View" />
<browser:addform
label="Add Layout Node"
@ -46,7 +45,6 @@
title="Layout Node"
description="A layout node controls the presentation of objects"
permission="zope.ManageContent"
view="AddLoopsLayoutNode.html"
/>
view="AddLoopsLayoutNode.html" />
</configure>