From 0b734d550f5b9d43e6d7be2b78f0521531f314ea Mon Sep 17 00:00:00 2001 From: helmutm Date: Fri, 20 Mar 2009 14:17:15 +0000 Subject: [PATCH] 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 --- common.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/common.py b/common.py index a9b3d97..7b9ac6d 100644 --- a/common.py +++ b/common.py @@ -311,13 +311,14 @@ class RelationSet(object): langInfo = None - def __init__(self, context, predicateName): + def __init__(self, context, predicateName, interface=None): self.adapted = context if isinstance(context, AdapterBase): self.context = context.context else: self.context = context self.predicateName = predicateName + self.interface = interface @Lazy def loopsRoot(self): @@ -349,7 +350,20 @@ class ParentRelationSet(RelationSet): if self.adapted.__is_dummy__: return 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): @@ -391,13 +405,14 @@ class TypeInstancesProperty(object): class RelationSetProperty(object): - def __init__(self, predicateName): + def __init__(self, predicateName, interface=None): self.predicateName = predicateName + self.interface = interface def __get__(self, inst, class_=None): if inst is None: return self - return self.factory(inst, self.predicateName) + return self.factory(inst, self.predicateName, self.interface) def __set__(self, inst, value): rs = self.factory(inst, self.predicateName)