IView.target attribute: implement with 1:n relation
git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@954 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
edf3e0ecf6
commit
535e2d3f3b
4 changed files with 24 additions and 16 deletions
11
README.txt
11
README.txt
|
@ -107,7 +107,7 @@ We first need a view manager:
|
|||
>>> views = loops['views']
|
||||
|
||||
The view space is typically built up with nodes; a node may be a top-level
|
||||
menu that may contain other nodes as menu items:
|
||||
menu that may contain other nodes as menu or content items:
|
||||
|
||||
>>> m1 = Node(u'Menu')
|
||||
>>> views['m1'] = m1
|
||||
|
@ -126,5 +126,12 @@ We can associate a node with a concept or directly with a resource via the
|
|||
view class's target attribute:
|
||||
|
||||
>>> m111.target = zope_info
|
||||
>>> m112.target = zope3
|
||||
>>> m111.target is zope_info
|
||||
True
|
||||
>>> m111.target = zope_info
|
||||
>>> m111.target is zope_info
|
||||
True
|
||||
>>> m111.target = zope3
|
||||
>>> m111.target is zope3
|
||||
True
|
||||
|
||||
|
|
|
@ -166,9 +166,9 @@
|
|||
permission="zope.ManageContent"
|
||||
set_schema=".interfaces.INode" />
|
||||
|
||||
<require
|
||||
<!--<require
|
||||
permission="zope.View"
|
||||
interface="zope.app.container.interfaces.IReadContainer" />
|
||||
interface="zope.app.container.interfaces.IReadContainer" />-->
|
||||
|
||||
</content>
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ from zope.interface import Interface, Attribute
|
|||
from zope.i18nmessageid import MessageFactory
|
||||
from zope import schema
|
||||
from zope.app.container.constraints import contains, containers
|
||||
from zope.app.container.interfaces import IContainer
|
||||
from zope.app.container.interfaces import IContainer, IOrderedContainer
|
||||
from zope.app.file.interfaces import IFile as IBaseFile
|
||||
from zope.app.folder.interfaces import IFolder
|
||||
|
||||
|
@ -153,7 +153,7 @@ class IResourceManagerContained(Interface):
|
|||
|
||||
class IView(Interface):
|
||||
""" A view is a user interface component that provides access to one
|
||||
or more concepts.
|
||||
or more concepts, resources, or other views.
|
||||
"""
|
||||
|
||||
title = schema.TextLine(
|
||||
|
@ -171,7 +171,7 @@ class IView(Interface):
|
|||
target = Attribute('Target object that is referenced by this view')
|
||||
|
||||
|
||||
class INode(IView):
|
||||
class INode(IView, IOrderedContainer):
|
||||
""" A node is a view that may contain other views, thus building a
|
||||
menu or folder hierarchy.
|
||||
"""
|
||||
|
|
19
view.py
19
view.py
|
@ -51,23 +51,24 @@ class View(object):
|
|||
description = property(getDescription, setDescription)
|
||||
|
||||
def getTarget(self):
|
||||
rels = getRelations(first=self)
|
||||
rels = getRelations(first=self, relationships=[TargetRelation])
|
||||
if len(rels) == 0:
|
||||
return None
|
||||
if len(rels) > 1:
|
||||
raise ValueError, 'There may be only one target for a View object.'
|
||||
return rels.next().second
|
||||
return list(rels)[0].second
|
||||
|
||||
def setTarget(self, target):
|
||||
return
|
||||
registry = zapi.getUtility(IRelationsRegistry)
|
||||
rels = registry.query(first=self)
|
||||
rels = list(registry.query(first=self, relationship=TargetRelation))
|
||||
if len(rels) > 0:
|
||||
if rels[0].second != target:
|
||||
registry.unregister(target)
|
||||
else:
|
||||
rel = relationship(self, concept)
|
||||
registry.register(rel)
|
||||
oldRel = rels[0]
|
||||
if oldRel.second is target:
|
||||
return
|
||||
else:
|
||||
registry.unregister(oldRel)
|
||||
rel = TargetRelation(self, target)
|
||||
registry.register(rel)
|
||||
|
||||
target = property(getTarget, setTarget)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue