let DummyRelationRegistry use real IntIds if available
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@1415 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
36acb9d8cf
commit
06dc2c17fb
1 changed files with 15 additions and 7 deletions
|
@ -24,6 +24,7 @@ $Id$
|
||||||
|
|
||||||
from persistent import Persistent
|
from persistent import Persistent
|
||||||
from persistent.interfaces import IPersistent
|
from persistent.interfaces import IPersistent
|
||||||
|
from zope import component
|
||||||
from zope.interface import Interface, Attribute, implements
|
from zope.interface import Interface, Attribute, implements
|
||||||
from zope.app import zapi
|
from zope.app import zapi
|
||||||
from zope.app.catalog.catalog import Catalog
|
from zope.app.catalog.catalog import Catalog
|
||||||
|
@ -54,9 +55,13 @@ class DummyRelationRegistry(object):
|
||||||
self.objects.append(relation)
|
self.objects.append(relation)
|
||||||
for attr in ('first', 'second', 'third',):
|
for attr in ('first', 'second', 'third',):
|
||||||
value = getattr(relation, attr, None)
|
value = getattr(relation, attr, None)
|
||||||
if value is not None and value not in self.objects:
|
if value is not None:
|
||||||
self.objects.append(value)
|
intids = component.queryUtility(IIntIds)
|
||||||
|
if intids is not None:
|
||||||
|
intids.register(value)
|
||||||
|
elif value not in self.objects:
|
||||||
|
self.objects.append(value)
|
||||||
|
|
||||||
def unregister(self, relation):
|
def unregister(self, relation):
|
||||||
if relation in self.relations:
|
if relation in self.relations:
|
||||||
self.relations.remove(relation)
|
self.relations.remove(relation)
|
||||||
|
@ -65,10 +70,13 @@ class DummyRelationRegistry(object):
|
||||||
def getUniqueIdForObject(self, obj):
|
def getUniqueIdForObject(self, obj):
|
||||||
if obj == '*': # wild card
|
if obj == '*': # wild card
|
||||||
return '*'
|
return '*'
|
||||||
|
intids = component.queryUtility(IIntIds)
|
||||||
|
if intids is not None:
|
||||||
|
return intids.register(obj)
|
||||||
if obj not in self.objects:
|
if obj not in self.objects:
|
||||||
self.objects.append(obj)
|
self.objects.append(obj)
|
||||||
return self.objects.index(obj)
|
return self.objects.index(obj)
|
||||||
|
|
||||||
def query(self, example=None, **kw):
|
def query(self, example=None, **kw):
|
||||||
result = []
|
result = []
|
||||||
criteria = {}
|
criteria = {}
|
||||||
|
@ -116,7 +124,7 @@ class RelationRegistry(Catalog):
|
||||||
# Allow the IntIds utility to get a DB connection:
|
# Allow the IntIds utility to get a DB connection:
|
||||||
relation.__parent__ = self
|
relation.__parent__ = self
|
||||||
self.index_doc(zapi.getUtility(IIntIds).register(relation), relation)
|
self.index_doc(zapi.getUtility(IIntIds).register(relation), relation)
|
||||||
|
|
||||||
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))
|
notify(RelationInvalidatedEvent(relation))
|
||||||
|
@ -152,7 +160,7 @@ class RelationRegistry(Catalog):
|
||||||
criteria[k] = (value, value)
|
criteria[k] = (value, value)
|
||||||
return self.searchResults(**criteria)
|
return self.searchResults(**criteria)
|
||||||
|
|
||||||
|
|
||||||
class IIndexableRelation(Interface):
|
class IIndexableRelation(Interface):
|
||||||
""" Provides the attributes needed for indexing relation objects in
|
""" Provides the attributes needed for indexing relation objects in
|
||||||
a catalog-based registry.
|
a catalog-based registry.
|
||||||
|
@ -238,7 +246,7 @@ def setRelationSingle(relation, forSecond=True):
|
||||||
registry.unregister(oldRel)
|
registry.unregister(oldRel)
|
||||||
registry.register(relation)
|
registry.register(relation)
|
||||||
|
|
||||||
|
|
||||||
# events and handlers
|
# events and handlers
|
||||||
|
|
||||||
class RelationInvalidatedEvent(ObjectEvent):
|
class RelationInvalidatedEvent(ObjectEvent):
|
||||||
|
|
Loading…
Add table
Reference in a new issue