source: main/waeup.kofa/trunk/src/waeup/kofa/catalog.py @ 9289

Last change on this file since 9289 was 9217, checked in by uli, 12 years ago

Merge changes from uli-async-update back into trunk.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.0 KB
RevLine 
[7193]1## $Id: catalog.py 9217 2012-09-21 11:21:05Z uli $
2##
3## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann
4## This program is free software; you can redistribute it and/or modify
5## it under the terms of the GNU General Public License as published by
6## the Free Software Foundation; either version 2 of the License, or
7## (at your option) any later version.
8##
9## This program is distributed in the hope that it will be useful,
10## but WITHOUT ANY WARRANTY; without even the implied warranty of
11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12## GNU General Public License for more details.
13##
14## You should have received a copy of the GNU General Public License
15## along with this program; if not, write to the Free Software
16## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17##
[5090]18"""Components to help cataloging and searching objects.
19"""
[3521]20import grok
[5090]21from hurry.query.interfaces import IQuery
22from hurry.query.query import Query
23from zope.catalog.catalog import ResultSet
[5091]24from zope.component import getUtility
[5090]25from zope.intid.interfaces import IIntIds
[7811]26from waeup.kofa.interfaces import IQueryResultItem
[3521]27
[6447]28# not yet used
[7819]29class KofaQuery(Query):
[6207]30    """A hurry.query-like query that supports also ``apply``.
31    """
32    grok.implements(IQuery)
[4789]33
[6207]34    def apply(self, query):
35        """Get a catalog's BTree set of intids conforming to a query.
36        """
37        return query.apply()
[5090]38
[6207]39    def searchResults(self, query):
40        """Get a set of ZODB objects conforming to a query.
41        """
42        results = self.apply(query)
43        if results is not None:
44            uidutil = getUtility(IIntIds)
45            results = ResultSet(results, uidutil)
46        return results
[5090]47
[7819]48grok.global_utility(KofaQuery)
[5090]49
[6447]50# not yet used
[4789]51class QueryResultItem(object):
[6207]52    grok.implements(IQueryResultItem)
53    url = None
54    title = None
55    description = None
[6116]56
[6207]57    def __init__(self, context, view):
58        self.context = context
59        self.url = view.url(context)
60        self.title = context.title
61        self.description = ''
Note: See TracBrowser for help on using the repository browser.