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
This commit is contained in:
parent
3dc2a3b24d
commit
e432727f60
3 changed files with 20 additions and 7 deletions
23
common.py
23
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):
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -536,7 +536,7 @@ class IndexAttributes(object):
|
|||
return creators
|
||||
|
||||
def identifier(self):
|
||||
return getName(self)
|
||||
return getName(self.context)
|
||||
|
||||
|
||||
class ResourceTypeSourceList(object):
|
||||
|
|
Loading…
Add table
Reference in a new issue