add relation set stuff for mapping relations to collection attributes
git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@2847 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
76cb439324
commit
7e2efcedfc
1 changed files with 44 additions and 0 deletions
44
common.py
44
common.py
|
@ -32,6 +32,7 @@ from zope.dublincore.zopedublincore import ScalarProperty
|
||||||
from zope.interface import implements
|
from zope.interface import implements
|
||||||
from zope.interface.interface import InterfaceClass
|
from zope.interface.interface import InterfaceClass
|
||||||
from zope.security.proxy import isinstance
|
from zope.security.proxy import isinstance
|
||||||
|
from zope.traversing.api import getName
|
||||||
|
|
||||||
from cybertools.storage.interfaces import IStorageInfo
|
from cybertools.storage.interfaces import IStorageInfo
|
||||||
from cybertools.typology.interfaces import IType
|
from cybertools.typology.interfaces import IType
|
||||||
|
@ -213,6 +214,49 @@ class NameChooser(BaseNameChooser):
|
||||||
'\xc4': 'Ae', '\xe4': 'ae', '\xd6': 'Oe', '\xf6': 'oe',
|
'\xc4': 'Ae', '\xe4': 'ae', '\xd6': 'Oe', '\xf6': 'oe',
|
||||||
'\xdc': 'Ue', '\xfc': 'ue', '\xdf': 'ss'}
|
'\xdc': 'Ue', '\xfc': 'ue', '\xdf': 'ss'}
|
||||||
|
|
||||||
|
|
||||||
|
# relation set: use relations of a certain predicate as a collection attribute
|
||||||
|
|
||||||
|
class ParentRelationSet(object):
|
||||||
|
|
||||||
|
def __init__(self, context, predicateName):
|
||||||
|
self.adapted = context
|
||||||
|
if isinstance(context, AdapterBase):
|
||||||
|
self.context = context.context
|
||||||
|
else:
|
||||||
|
self.context = context
|
||||||
|
self.predicateName = predicateName
|
||||||
|
|
||||||
|
@Lazy
|
||||||
|
def loopsRoot(self):
|
||||||
|
return self.context.getLoopsRoot()
|
||||||
|
|
||||||
|
@Lazy
|
||||||
|
def conceptManager(self):
|
||||||
|
return self.loopsRoot.getConceptManager()
|
||||||
|
|
||||||
|
@Lazy
|
||||||
|
def predicate(self):
|
||||||
|
return self.conceptManager[self.predicateName]
|
||||||
|
|
||||||
|
def __iter__(self):
|
||||||
|
for c in self.context.getParents([self.predicate]):
|
||||||
|
yield adapted(c)
|
||||||
|
|
||||||
|
|
||||||
|
class ChildRelationSet(ParentRelationSet):
|
||||||
|
|
||||||
|
def add(self, related):
|
||||||
|
self.context.assignChild(related, self.predicate)
|
||||||
|
|
||||||
|
def remove(self, related):
|
||||||
|
self.context.deassignChild(related, [self.predicate])
|
||||||
|
|
||||||
|
def __iter__(self):
|
||||||
|
for c in self.context.getChildren([self.predicate]):
|
||||||
|
yield adapted(c)
|
||||||
|
|
||||||
|
|
||||||
# caching (TBD)
|
# caching (TBD)
|
||||||
|
|
||||||
def cached(obj):
|
def cached(obj):
|
||||||
|
|
Loading…
Add table
Reference in a new issue