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)) | ||||
| 
 | ||||
|     def getUniqueIdForObject(self, obj): | ||||
|         if obj in self.objects: | ||||
|         if obj == '*': # wild card | ||||
|             return '*' | ||||
|         if obj not in self.objects: | ||||
|             self.objects.append(obj) | ||||
|         return self.objects.index(obj) | ||||
|         return None | ||||
|      | ||||
|     def query(self, example=None, **kw): | ||||
|         result = [] | ||||
|  | @ -82,10 +84,16 @@ class DummyRelationRegistry(object): | |||
|                 continue | ||||
|             hit = True | ||||
|             for k in criteria: | ||||
|                 if ((k == 'relationship' | ||||
|                         and r.getPredicateName() != criteria[k].getPredicateName()) | ||||
|                  or (k != 'relationship' | ||||
|                         and (not hasattr(r, k) or getattr(r, k) != criteria[k]))): | ||||
|                 crit = criteria[k] | ||||
|                 if k == 'relationship': | ||||
|                     critpn = crit.getPredicateName() | ||||
|                     if ((critpn.endswith('*') | ||||
|                                 and not r.getPredicateName().startswith(critpn[:-1])) | ||||
|                             and r.getPredicateName() != critpn): | ||||
|                         hit = False | ||||
|                         break | ||||
|                 else: | ||||
|                     if not hasattr(r, k) or getattr(r, k) != crit: | ||||
|                         hit = False | ||||
|                         break | ||||
|             if hit: | ||||
|  | @ -115,7 +123,9 @@ class RelationRegistry(Catalog): | |||
|         notify(RelationInvalidatedEvent(relation)) | ||||
| 
 | ||||
|     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): | ||||
|         intIds = zapi.getUtility(IIntIds) | ||||
|  | @ -136,13 +146,13 @@ class RelationRegistry(Catalog): | |||
|                 criteria[k] = intIds.getId(kw[k]) | ||||
|         for k in criteria: | ||||
|             # 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) | ||||
| 
 | ||||
| #BBB | ||||
| #RelationsRegistry = RelationRegistry | ||||
| 
 | ||||
| 
 | ||||
|      | ||||
| class IIndexableRelation(Interface): | ||||
|     """ Provides the attributes needed for indexing relation objects in | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 helmutm
						helmutm