add interface as additional selection argument for retrieving relation set values
git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@3285 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
a5c44e979c
commit
0b734d550f
1 changed files with 19 additions and 4 deletions
23
common.py
23
common.py
|
@ -311,13 +311,14 @@ class RelationSet(object):
|
||||||
|
|
||||||
langInfo = None
|
langInfo = None
|
||||||
|
|
||||||
def __init__(self, context, predicateName):
|
def __init__(self, context, predicateName, interface=None):
|
||||||
self.adapted = context
|
self.adapted = context
|
||||||
if isinstance(context, AdapterBase):
|
if isinstance(context, AdapterBase):
|
||||||
self.context = context.context
|
self.context = context.context
|
||||||
else:
|
else:
|
||||||
self.context = context
|
self.context = context
|
||||||
self.predicateName = predicateName
|
self.predicateName = predicateName
|
||||||
|
self.interface = interface
|
||||||
|
|
||||||
@Lazy
|
@Lazy
|
||||||
def loopsRoot(self):
|
def loopsRoot(self):
|
||||||
|
@ -349,7 +350,20 @@ class ParentRelationSet(RelationSet):
|
||||||
if self.adapted.__is_dummy__:
|
if self.adapted.__is_dummy__:
|
||||||
return
|
return
|
||||||
for c in self.context.getParents([self.predicate]):
|
for c in self.context.getParents([self.predicate]):
|
||||||
yield adapted(c, langInfo=self.langInfo)
|
a = adapted(c, langInfo=self.langInfo)
|
||||||
|
if self.interface is None or self.interface.providedBy(a):
|
||||||
|
yield a
|
||||||
|
|
||||||
|
def getRelations(self, check=None):
|
||||||
|
if self.adapted.__is_dummy__:
|
||||||
|
return
|
||||||
|
for r in self.context.getParentRelations([self.predicate]):
|
||||||
|
if check is None or check(r):
|
||||||
|
yield r
|
||||||
|
|
||||||
|
def getRelated(self, check=None):
|
||||||
|
for r in self.getRelations(check):
|
||||||
|
yield adapted(r.first, langInfo=self.langInfo)
|
||||||
|
|
||||||
|
|
||||||
class ChildRelationSet(RelationSet):
|
class ChildRelationSet(RelationSet):
|
||||||
|
@ -391,13 +405,14 @@ class TypeInstancesProperty(object):
|
||||||
|
|
||||||
class RelationSetProperty(object):
|
class RelationSetProperty(object):
|
||||||
|
|
||||||
def __init__(self, predicateName):
|
def __init__(self, predicateName, interface=None):
|
||||||
self.predicateName = predicateName
|
self.predicateName = predicateName
|
||||||
|
self.interface = interface
|
||||||
|
|
||||||
def __get__(self, inst, class_=None):
|
def __get__(self, inst, class_=None):
|
||||||
if inst is None:
|
if inst is None:
|
||||||
return self
|
return self
|
||||||
return self.factory(inst, self.predicateName)
|
return self.factory(inst, self.predicateName, self.interface)
|
||||||
|
|
||||||
def __set__(self, inst, value):
|
def __set__(self, inst, value):
|
||||||
rs = self.factory(inst, self.predicateName)
|
rs = self.factory(inst, self.predicateName)
|
||||||
|
|
Loading…
Add table
Reference in a new issue