Added method IRelationRegistry.getUniqueIdForObject()
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@1090 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
a5cb31fa47
commit
3fe7c3ff00
3 changed files with 36 additions and 1 deletions
|
@ -159,6 +159,14 @@ It is also possible to remove a relation from the relation registry:
|
|||
>>> nyRels[0].first == kirk
|
||||
True
|
||||
|
||||
The relation registry also provides unique ids for all relations
|
||||
registered and all objects taking part in these relations. This unique
|
||||
ids may be used e.g. if relationships or predicates are themselves
|
||||
content objects.
|
||||
|
||||
>>> relations.getUniqueIdForObject(kirk)
|
||||
7
|
||||
|
||||
|
||||
Triadic Relations
|
||||
~~~~~~~~~~~~~~~~~
|
||||
|
@ -305,6 +313,12 @@ a relation registry; it allows to query for more than one relationship:
|
|||
>>> len(getRelations(first=clark, relationships=[LivesIn]))
|
||||
1
|
||||
|
||||
The relation registry also supports the getUniqueIdForObject() method that
|
||||
just returns the intid of the object given:
|
||||
|
||||
>>> relations.getUniqueIdForObject(kirk)
|
||||
1
|
||||
|
||||
|
||||
Handling object removal
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
|
|
@ -131,6 +131,11 @@ class IRelationRegistryUpdate(Interface):
|
|||
""" Remove the relation given from this registry.
|
||||
"""
|
||||
|
||||
def getUniqueIdForObject(object):
|
||||
""" Return an identifier for the object given that is unique at
|
||||
least within the scope of this registry.
|
||||
"""
|
||||
|
||||
|
||||
class IRelationRegistryQuery(Interface):
|
||||
""" Interface for querying a relation registry.
|
||||
|
@ -155,4 +160,3 @@ class IRelationRegistry(IRelationRegistryUpdate, IRelationRegistryQuery):
|
|||
implemented as a local utility .
|
||||
"""
|
||||
|
||||
|
||||
|
|
|
@ -45,15 +45,27 @@ class DummyRelationRegistry(object):
|
|||
|
||||
def __init__(self):
|
||||
self.relations = []
|
||||
self.objects = []
|
||||
|
||||
def register(self, relation):
|
||||
if relation not in self.relations:
|
||||
self.relations.append(relation)
|
||||
if relation not in self.objects:
|
||||
self.objects.append(relation)
|
||||
for attr in ('first', 'second', 'third',):
|
||||
value = getattr(relation, attr, None)
|
||||
if value is not None and value not in self.objects:
|
||||
self.objects.append(value)
|
||||
|
||||
def unregister(self, relation):
|
||||
if relation in self.relations:
|
||||
self.relations.remove(relation)
|
||||
notify(RelationInvalidatedEvent(relation))
|
||||
|
||||
def getUniqueIdForObject(self, obj):
|
||||
if obj in self.objects:
|
||||
return self.objects.index(obj)
|
||||
return None
|
||||
|
||||
def query(self, example=None, **kw):
|
||||
result = []
|
||||
|
@ -66,6 +78,8 @@ class DummyRelationRegistry(object):
|
|||
criteria['relationship'] = example
|
||||
criteria.update(kw)
|
||||
for r in self.relations:
|
||||
if r is None:
|
||||
continue
|
||||
hit = True
|
||||
for k in criteria:
|
||||
if ((k == 'relationship'
|
||||
|
@ -100,6 +114,9 @@ class RelationRegistry(Catalog):
|
|||
self.unindex_doc(zapi.getUtility(IIntIds).getId(relation))
|
||||
notify(RelationInvalidatedEvent(relation))
|
||||
|
||||
def getUniqueIdForObject(self, obj):
|
||||
return zapi.getUtility(IIntIds).getId(obj)
|
||||
|
||||
def query(self, example=None, **kw):
|
||||
intIds = zapi.getUtility(IIntIds)
|
||||
criteria = {}
|
||||
|
|
Loading…
Add table
Reference in a new issue