bug fixes for relation framework
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@1042 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
b4182316af
commit
b22a3b2a8d
1 changed files with 11 additions and 12 deletions
|
@ -88,7 +88,8 @@ class RelationsRegistry(Catalog):
|
||||||
|
|
||||||
def unregister(self, relation):
|
def unregister(self, relation):
|
||||||
self.unindex_doc(zapi.getUtility(IIntIds).getId(relation))
|
self.unindex_doc(zapi.getUtility(IIntIds).getId(relation))
|
||||||
|
notify(RelationInvalidatedEvent(relation))
|
||||||
|
|
||||||
def query(self, example=None, **kw):
|
def query(self, example=None, **kw):
|
||||||
for k in kw:
|
for k in kw:
|
||||||
if k == 'relationship':
|
if k == 'relationship':
|
||||||
|
@ -140,9 +141,9 @@ def getRelations(first=None, second=None, third=None, relationships=None):
|
||||||
"""
|
"""
|
||||||
registry = zapi.getUtility(IRelationsRegistry)
|
registry = zapi.getUtility(IRelationsRegistry)
|
||||||
query = {}
|
query = {}
|
||||||
if first: query['first'] = first
|
if first is not None: query['first'] = first
|
||||||
if second: query['second'] = second
|
if second is not None: query['second'] = second
|
||||||
if third: query['third'] = third
|
if third is not None: query['third'] = third
|
||||||
if not relationships:
|
if not relationships:
|
||||||
return registry.query(**query)
|
return registry.query(**query)
|
||||||
else:
|
else:
|
||||||
|
@ -160,23 +161,21 @@ class RelationInvalidatedEvent(ObjectEvent):
|
||||||
|
|
||||||
|
|
||||||
def invalidateRelations(context, event):
|
def invalidateRelations(context, event):
|
||||||
""" Handles IObjectRemoved event: sends out an IRelationInvalidatedEvent
|
""" Handles IObjectRemoved event: unregisters
|
||||||
for all relations the object to be removed is involved in.
|
all relations the object to be removed is involved in.
|
||||||
"""
|
"""
|
||||||
relations = []
|
relations = []
|
||||||
registry = zapi.getUtility(IRelationsRegistry)
|
registry = zapi.getUtility(IRelationsRegistry)
|
||||||
for attr in ('first', 'second', 'third'):
|
for attr in ('first', 'second', 'third'):
|
||||||
relations = registry.query(**{attr: context})
|
relations = registry.query(**{attr: context})
|
||||||
for relation in relations:
|
for relation in relations:
|
||||||
notify(RelationInvalidatedEvent(relation))
|
registry.unregister(relation)
|
||||||
|
|
||||||
def removeRelation(context, event):
|
def removeRelation(context, event):
|
||||||
""" Handles IRelationInvalidatedEvent by unregistering the relation
|
""" Handles IRelationInvalidatedEvent by removing the relation
|
||||||
and removing it from its container (if appropriate) and the IntIds
|
(that should be already unregistered from the relations registry)
|
||||||
utility.
|
from its container (if appropriate) and the IntIds utility.
|
||||||
"""
|
"""
|
||||||
registry = zapi.getUtility(IRelationsRegistry)
|
|
||||||
registry.unregister(context)
|
|
||||||
if ILocation.providedBy(context):
|
if ILocation.providedBy(context):
|
||||||
parent = zapi.getParent(context)
|
parent = zapi.getParent(context)
|
||||||
if parent is not None:
|
if parent is not None:
|
||||||
|
|
Loading…
Add table
Reference in a new issue