work in progress: layout management
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@2909 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
e9bc7d0b19
commit
2218a6734f
3 changed files with 26 additions and 11 deletions
|
@ -44,12 +44,14 @@ class LayoutManager(object):
|
|||
for name, layout in component.getUtilitiesFor(ILayout):
|
||||
region = result.setdefault(layout.regionName,
|
||||
Region(layout.regionName))
|
||||
# layout.name = name
|
||||
region.layouts.append(layout)
|
||||
return result
|
||||
|
||||
def getLayouts(self, key, instance):
|
||||
region = self.regions.get(key)
|
||||
return sorted(instance.getLayouts(region), key=lambda x: x.order)
|
||||
return sorted(instance.getLayouts(region),
|
||||
key=lambda x: x.template.order)
|
||||
|
||||
|
||||
class Layout(Template):
|
||||
|
@ -83,8 +85,15 @@ class LayoutInstance(object):
|
|||
return self.template.renderer
|
||||
|
||||
def getLayouts(self, region):
|
||||
""" Return sublayout instances.
|
||||
"""
|
||||
if region is None:
|
||||
return []
|
||||
result = []
|
||||
sublayouts = self.template.sublayouts
|
||||
return [l for l in region.layouts
|
||||
if sublayouts is None or l.name in 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
|
||||
|
|
|
@ -56,13 +56,23 @@ class BaseView(object):
|
|||
class Page(BaseView):
|
||||
|
||||
layoutName = 'page'
|
||||
layoutNames = ['page']
|
||||
|
||||
@Lazy
|
||||
def rootView(self):
|
||||
return self
|
||||
|
||||
def __call__(self):
|
||||
layout = component.getUtility(ILayout, name=self.layoutName)
|
||||
# use LayoutManager to retrieve page region;
|
||||
# then search in self.layoutNames for a fit
|
||||
manager = component.getUtility(ILayoutManager)
|
||||
layouts = manager.regions['page'].layouts
|
||||
layoutNames = layouts.keys()
|
||||
layout = None
|
||||
for n in self.layoutNames:
|
||||
if n in layoutNames:
|
||||
layout = layouts[n]
|
||||
break
|
||||
instance = ILayoutInstance(self.context)
|
||||
instance.template = layout
|
||||
view = LayoutView(instance, self.request, name='page',
|
||||
|
@ -97,10 +107,6 @@ class LayoutView(BaseView):
|
|||
def layouts(self):
|
||||
return ViewLayouts(self)
|
||||
|
||||
@Lazy
|
||||
def resources(self):
|
||||
return ViewResources(self)
|
||||
|
||||
def getLayoutsFor(self, key):
|
||||
manager = component.getUtility(ILayoutManager)
|
||||
return manager.getLayouts('.'.join((self.name, key)), self.context)
|
||||
|
@ -116,9 +122,7 @@ class ViewLayouts(object):
|
|||
def __getitem__(self, key):
|
||||
view = self.view
|
||||
subviews = []
|
||||
for layout in view.getLayoutsFor(key):
|
||||
instance = ILayoutInstance(view.client)
|
||||
instance.template = layout
|
||||
for instance in view.getLayoutsFor(key):
|
||||
v = LayoutView(instance, view.request, name=key,
|
||||
parent=view, page=view.page)
|
||||
instance.view = v
|
||||
|
|
|
@ -78,6 +78,8 @@ class ILayout(ITemplate):
|
|||
|
||||
renderer = Attribute(u'An object responsible for rendering the layout.')
|
||||
order = Attribute(u'A number that may be used as a sorting key.')
|
||||
sublayouts = Attribute(u'A set of names explicitly specifying sub-layouts '
|
||||
u'for this layout.')
|
||||
|
||||
|
||||
class ILayoutComponent(IComponent):
|
||||
|
|
Loading…
Add table
Reference in a new issue