Work in progress: reorganized relation classes; some preliminary work on views
git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@849 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
0ab81ca2e0
commit
edf3e0ecf6
5 changed files with 60 additions and 62 deletions
|
@ -89,7 +89,7 @@ We can associate a resource with a concept by assigning it to the concept:
|
|||
[<loops.resource.Document ...>]
|
||||
|
||||
The resource also provides access to the associated concepts (or views, see
|
||||
below):
|
||||
below) via the getClients() method:
|
||||
|
||||
>>> conc = zope_info.getClients()
|
||||
>>> len(conc)
|
||||
|
@ -122,5 +122,9 @@ menu that may contain other nodes as menu items:
|
|||
>>> m112.description
|
||||
u''
|
||||
|
||||
We can associate a node with a concept or directly with a resource:
|
||||
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
|
||||
|
||||
|
|
27
concept.py
27
concept.py
|
@ -17,7 +17,7 @@
|
|||
#
|
||||
|
||||
"""
|
||||
Definition of the Concept class.
|
||||
Definition of the Concept and related classes.
|
||||
|
||||
$Id$
|
||||
"""
|
||||
|
@ -34,9 +34,22 @@ from cybertools.relation.registry import IRelationsRegistry, getRelations
|
|||
from interfaces import IConcept
|
||||
from interfaces import IConceptManager, IConceptManagerContained
|
||||
from interfaces import ILoopsContained
|
||||
from relations import ConceptRelation, ConceptResourceRelation
|
||||
|
||||
|
||||
# relation classes
|
||||
|
||||
class ConceptRelation(DyadicRelation):
|
||||
""" A relation between concept objects.
|
||||
"""
|
||||
|
||||
|
||||
class ResourceRelation(DyadicRelation):
|
||||
""" A relation between a concept and a resource object.
|
||||
"""
|
||||
|
||||
|
||||
# concept
|
||||
|
||||
class Concept(Contained, Persistent):
|
||||
|
||||
implements(IConcept, IConceptManagerContained)
|
||||
|
@ -71,6 +84,8 @@ class Concept(Contained, Persistent):
|
|||
# TODO (?): avoid duplicates
|
||||
|
||||
def deassignConcept(self, concept, relationships=None):
|
||||
if relationships is None:
|
||||
relationships = [ConceptRelation]
|
||||
registry = zapi.getUtility(IRelationsRegistry)
|
||||
relations = registry.query(first=self, second=concept,
|
||||
relationships=relationships)
|
||||
|
@ -81,17 +96,19 @@ class Concept(Contained, Persistent):
|
|||
|
||||
def getResources(self, relationships=None):
|
||||
if relationships is None:
|
||||
relationships = [ConceptResourceRelation]
|
||||
relationships = [ResourceRelation]
|
||||
rels = getRelations(first=self, relationships=relationships)
|
||||
return [r.second for r in rels]
|
||||
# TODO: sort...
|
||||
|
||||
def assignResource(self, resource, relationship=ConceptResourceRelation):
|
||||
def assignResource(self, resource, relationship=ResourceRelation):
|
||||
registry = zapi.getUtility(IRelationsRegistry)
|
||||
registry.register(relationship(self, resource))
|
||||
# TODO (?): avoid duplicates
|
||||
|
||||
def deassignResource(self, resource, relationships=None):
|
||||
if relationships is None:
|
||||
relationships = [ResourceRelation]
|
||||
registry = zapi.getUtility(IRelationsRegistry)
|
||||
relations = registry.query(first=self, second=resource,
|
||||
relationships=relationships)
|
||||
|
@ -99,6 +116,8 @@ class Concept(Contained, Persistent):
|
|||
registry.unregister(relation)
|
||||
|
||||
|
||||
# concept manager
|
||||
|
||||
class ConceptManager(BTreeContainer):
|
||||
|
||||
implements(IConceptManager, ILoopsContained)
|
||||
|
|
|
@ -22,7 +22,7 @@ loops interface definitions.
|
|||
$Id$
|
||||
"""
|
||||
|
||||
from zope.interface import Interface
|
||||
from zope.interface import Interface, Attribute
|
||||
from zope.i18nmessageid import MessageFactory
|
||||
from zope import schema
|
||||
from zope.app.container.constraints import contains, containers
|
||||
|
@ -168,10 +168,8 @@ class IView(Interface):
|
|||
default=u'',
|
||||
required=False)
|
||||
|
||||
def getConcepts():
|
||||
""" Return an ordered sequence of concepts referenced by this view.
|
||||
"""
|
||||
|
||||
target = Attribute('Target object that is referenced by this view')
|
||||
|
||||
|
||||
class INode(IView):
|
||||
""" A node is a view that may contain other views, thus building a
|
||||
|
|
49
relations.py
49
relations.py
|
@ -1,49 +0,0 @@
|
|||
#
|
||||
# Copyright (c) 2005 Helmut Merz helmutm@cy55.de
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
"""
|
||||
Definition of relation classes.
|
||||
|
||||
$Id$
|
||||
"""
|
||||
|
||||
from zope.app import zapi
|
||||
from zope.interface import implements
|
||||
|
||||
from cybertools.relation import DyadicRelation
|
||||
|
||||
|
||||
class ConceptRelation(DyadicRelation):
|
||||
""" A relation between concept objects.
|
||||
"""
|
||||
|
||||
|
||||
class ConceptResourceRelation(DyadicRelation):
|
||||
""" A relation between a concept and a resource object.
|
||||
"""
|
||||
|
||||
|
||||
class ViewConceptRelation(DyadicRelation):
|
||||
""" A relation between a view and a concept object.
|
||||
"""
|
||||
|
||||
|
||||
class ViewResourceRelation(DyadicRelation):
|
||||
""" A relation between a view and a resource object.
|
||||
"""
|
||||
|
30
view.py
30
view.py
|
@ -28,6 +28,8 @@ from zope.app.container.contained import Contained
|
|||
from zope.app.container.ordered import OrderedContainer
|
||||
from zope.interface import implements
|
||||
from persistent import Persistent
|
||||
from cybertools.relation import DyadicRelation
|
||||
from cybertools.relation.registry import IRelationsRegistry, getRelations
|
||||
|
||||
from interfaces import IView, INode
|
||||
from interfaces import IViewManager, INodeContained
|
||||
|
@ -48,13 +50,32 @@ class View(object):
|
|||
def setDescription(self, description): self._description = description
|
||||
description = property(getDescription, setDescription)
|
||||
|
||||
def getTarget(self):
|
||||
rels = getRelations(first=self)
|
||||
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
|
||||
|
||||
def setTarget(self, target):
|
||||
return
|
||||
registry = zapi.getUtility(IRelationsRegistry)
|
||||
rels = registry.query(first=self)
|
||||
if len(rels) > 0:
|
||||
if rels[0].second != target:
|
||||
registry.unregister(target)
|
||||
else:
|
||||
rel = relationship(self, concept)
|
||||
registry.register(rel)
|
||||
|
||||
target = property(getTarget, setTarget)
|
||||
|
||||
def __init__(self, title=u'', description=u''):
|
||||
self.title = title
|
||||
self.description = description
|
||||
super(View, self).__init__()
|
||||
|
||||
def getConcepts(self):
|
||||
return []
|
||||
|
||||
|
||||
class Node(View, OrderedContainer):
|
||||
|
@ -67,3 +88,8 @@ class ViewManager(BTreeContainer):
|
|||
implements(IViewManager, ILoopsContained)
|
||||
|
||||
|
||||
class TargetRelation(DyadicRelation):
|
||||
""" A relation between a view and a concept or resource object.
|
||||
"""
|
||||
|
||||
|
Loading…
Add table
Reference in a new issue