From 535e2d3f3b442c1924d9f0ab39c70e96c3765143 Mon Sep 17 00:00:00 2001 From: helmutm Date: Wed, 21 Dec 2005 08:02:39 +0000 Subject: [PATCH] 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 --- README.txt | 11 +++++++++-- configure.zcml | 4 ++-- interfaces.py | 6 +++--- view.py | 19 ++++++++++--------- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/README.txt b/README.txt index edae630..0c78ff6 100755 --- a/README.txt +++ b/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 diff --git a/configure.zcml b/configure.zcml index 78d48dd..cd66ab6 100644 --- a/configure.zcml +++ b/configure.zcml @@ -166,9 +166,9 @@ permission="zope.ManageContent" set_schema=".interfaces.INode" /> - + interface="zope.app.container.interfaces.IReadContainer" />--> diff --git a/interfaces.py b/interfaces.py index 848c576..a97b561 100644 --- a/interfaces.py +++ b/interfaces.py @@ -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. """ diff --git a/view.py b/view.py index 8e4ca54..747ee3c 100644 --- a/view.py +++ b/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)