Allow wildcard queries
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@1096 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
fb86c0f6ca
commit
9f0cfba50d
1 changed files with 25 additions and 15 deletions
|
@ -63,9 +63,11 @@ class DummyRelationRegistry(object):
|
||||||
notify(RelationInvalidatedEvent(relation))
|
notify(RelationInvalidatedEvent(relation))
|
||||||
|
|
||||||
def getUniqueIdForObject(self, obj):
|
def getUniqueIdForObject(self, obj):
|
||||||
if obj in self.objects:
|
if obj == '*': # wild card
|
||||||
return self.objects.index(obj)
|
return '*'
|
||||||
return None
|
if obj not in self.objects:
|
||||||
|
self.objects.append(obj)
|
||||||
|
return self.objects.index(obj)
|
||||||
|
|
||||||
def query(self, example=None, **kw):
|
def query(self, example=None, **kw):
|
||||||
result = []
|
result = []
|
||||||
|
@ -82,12 +84,18 @@ class DummyRelationRegistry(object):
|
||||||
continue
|
continue
|
||||||
hit = True
|
hit = True
|
||||||
for k in criteria:
|
for k in criteria:
|
||||||
if ((k == 'relationship'
|
crit = criteria[k]
|
||||||
and r.getPredicateName() != criteria[k].getPredicateName())
|
if k == 'relationship':
|
||||||
or (k != 'relationship'
|
critpn = crit.getPredicateName()
|
||||||
and (not hasattr(r, k) or getattr(r, k) != criteria[k]))):
|
if ((critpn.endswith('*')
|
||||||
hit = False
|
and not r.getPredicateName().startswith(critpn[:-1]))
|
||||||
break
|
and r.getPredicateName() != critpn):
|
||||||
|
hit = False
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
if not hasattr(r, k) or getattr(r, k) != crit:
|
||||||
|
hit = False
|
||||||
|
break
|
||||||
if hit:
|
if hit:
|
||||||
result.append(r)
|
result.append(r)
|
||||||
return result
|
return result
|
||||||
|
@ -115,7 +123,9 @@ class RelationRegistry(Catalog):
|
||||||
notify(RelationInvalidatedEvent(relation))
|
notify(RelationInvalidatedEvent(relation))
|
||||||
|
|
||||||
def getUniqueIdForObject(self, obj):
|
def getUniqueIdForObject(self, obj):
|
||||||
return zapi.getUtility(IIntIds).getId(obj)
|
if obj == '*': # wild card
|
||||||
|
return '*'
|
||||||
|
return zapi.getUtility(IIntIds).queryId(obj)
|
||||||
|
|
||||||
def query(self, example=None, **kw):
|
def query(self, example=None, **kw):
|
||||||
intIds = zapi.getUtility(IIntIds)
|
intIds = zapi.getUtility(IIntIds)
|
||||||
|
@ -136,13 +146,13 @@ class RelationRegistry(Catalog):
|
||||||
criteria[k] = intIds.getId(kw[k])
|
criteria[k] = intIds.getId(kw[k])
|
||||||
for k in criteria:
|
for k in criteria:
|
||||||
# set min, max
|
# set min, max
|
||||||
criteria[k] = (criteria[k], criteria[k])
|
value = criteria[k]
|
||||||
|
if k == 'relationship' and value.endswith('*'):
|
||||||
|
criteria[k] = (value[:-1], value[:-1] + '\x7f')
|
||||||
|
else:
|
||||||
|
criteria[k] = (value, value)
|
||||||
return self.searchResults(**criteria)
|
return self.searchResults(**criteria)
|
||||||
|
|
||||||
#BBB
|
|
||||||
#RelationsRegistry = RelationRegistry
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class IIndexableRelation(Interface):
|
class IIndexableRelation(Interface):
|
||||||
""" Provides the attributes needed for indexing relation objects in
|
""" Provides the attributes needed for indexing relation objects in
|
||||||
|
|
Loading…
Add table
Reference in a new issue