Changeset 9767 for main/waeup.kofa/trunk/src/waeup
- Timestamp:
- 5 Dec 2012, 06:03:12 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/catalog.py
r9217 r9767 22 22 from hurry.query.query import Query 23 23 from zope.catalog.catalog import ResultSet 24 from zope.component import getUtility 24 from zope.catalog.interfaces import ICatalog 25 from zope.component import getUtility, queryUtility 26 from zope.interface import implementer 25 27 from zope.intid.interfaces import IIntIds 26 from waeup.kofa.interfaces import IQueryResultItem 28 from waeup.kofa.interfaces import ( 29 IQueryResultItem, IFilteredQuery, IFilteredCatalogQuery) 27 30 28 31 # not yet used 32 @implementer(IQuery) 29 33 class KofaQuery(Query): 30 34 """A hurry.query-like query that supports also ``apply``. 31 35 """ 32 grok.implements(IQuery)33 34 36 def apply(self, query): 35 37 """Get a catalog's BTree set of intids conforming to a query. … … 49 51 50 52 # not yet used 53 @implementer(IQueryResultItem) 51 54 class QueryResultItem(object): 52 grok.implements(IQueryResultItem)53 55 url = None 54 56 title = None … … 60 62 self.title = context.title 61 63 self.description = '' 64 65 @implementer(IFilteredQuery) 66 class FilteredQueryBase(object): 67 """A filter to find objects that match certain parameters. 68 """ 69 defaults = dict() 70 71 def __init__(self, **kw): 72 self._kw = dict(self.defaults) 73 self._kw.update(kw) 74 return 75 76 def query(self, context=None): 77 err_msg = 'class %s does not implement the query() method.' % ( 78 self.__class__.__name__, ) 79 raise NotImplementedError(err_msg) 80 81 @implementer(IFilteredCatalogQuery) 82 class FilteredCatalogQueryBase(FilteredQueryBase): 83 cat_name = None 84 85 def query_catalog(self, catalog): 86 query = dict() 87 for idx_name, value in self._kw.items(): 88 if not isinstance(value, tuple): 89 value = (value, value) 90 query[idx_name] = value 91 result = catalog.searchResults(**query) 92 return result 93 94 def query(self): 95 catalog = queryUtility( 96 ICatalog, name=self.cat_name, default=None) 97 if catalog is None: 98 return [] 99 return self.query_catalog(catalog)
Note: See TracChangeset for help on using the changeset viewer.