From e432727f60059207e3f16a39a72d04530b1dfeeb Mon Sep 17 00:00:00 2001 From: helmutm Date: Tue, 16 Sep 2008 12:07:12 +0000 Subject: [PATCH] use new kind of generic attributes/properties: TypeInstances, RelationSet properties git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@2887 fd906abe-77d9-0310-91a1-e0d9ade77398 --- common.py | 23 ++++++++++++++++++----- concept.py | 2 +- resource.py | 2 +- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/common.py b/common.py index 763c8ac..a8ca7a1 100644 --- a/common.py +++ b/common.py @@ -221,8 +221,6 @@ class NameChooser(BaseNameChooser): # virtual attributes/properties -#class ContainerAttribute(object): -#class ContainedCollection(object): class TypeInstances(object): """ Use objects within a ConceptManager object for a collection attribute. """ @@ -257,11 +255,13 @@ class TypeInstances(object): return adapted(c) def remove(self, id): - del self.context[self.prefix + id] + obj = self.get(id) + if obj is None: + raise KeyError(id) + else: + del self.context[getName(obj.context)] def get(self, id, default=None, langInfo=None): - #return adapted(self.context.get(self.prefix + id, default), - # langInfo=self.langInfo) from loops.expert import query result = (query.Identifier(id) & query.Type(self.typeToken)).apply() for obj in query.getObjects(result): @@ -336,6 +336,19 @@ class ChildRelationSet(RelationSet): # property descriptors +class TypeInstancesProperty(object): + + def __init__(self, typeName, idAttr='name', prefix=''): + self.typeName = typeName + self.idAttr = idAttr + self.prefix = prefix + + def __get__(self, inst, class_=None): + if inst is None: + return self + return TypeInstances(inst.context, self.typeName, self.idAttr, self.prefix) + + class RelationSetProperty(object): def __init__(self, predicateName): diff --git a/concept.py b/concept.py index b41d691..4bf3ab6 100644 --- a/concept.py +++ b/concept.py @@ -439,7 +439,7 @@ class IndexAttributes(object): def identifier(self): id = getattr(self.adapted, 'identifier', None) if id is None: - return getName(self) + return getName(self.context) return id diff --git a/resource.py b/resource.py index 728554d..778679a 100644 --- a/resource.py +++ b/resource.py @@ -536,7 +536,7 @@ class IndexAttributes(object): return creators def identifier(self): - return getName(self) + return getName(self.context) class ResourceTypeSourceList(object):