source: main/waeup.sirp/trunk/src/waeup/sirp/catalog.py @ 6374

Last change on this file since 6374 was 6207, checked in by Henrik Bettermann, 13 years ago

Fix indentation. We use only 4 whitespaces not 5. Remove #BBB.

  • Property svn:eol-style set to native
File size: 1.6 KB
RevLine 
[5090]1"""Components to help cataloging and searching objects.
2"""
[3521]3import grok
[5091]4from grok import index
[3521]5from hurry.query import Eq
[5090]6from hurry.query.interfaces import IQuery
7from hurry.query.query import Query
8from zope.catalog.catalog import ResultSet
[5091]9from zope.component import getUtility
[5090]10from zope.intid.interfaces import IIntIds
11
[4920]12from waeup.sirp.app import University
[5007]13from waeup.sirp.interfaces import IQueryResultItem
[4920]14from waeup.sirp.student.interfaces import IStudent
[3521]15
[5090]16class WAeUPQuery(Query):
[6207]17    """A hurry.query-like query that supports also ``apply``.
18    """
19    grok.implements(IQuery)
[4789]20
[6207]21    def apply(self, query):
22        """Get a catalog's BTree set of intids conforming to a query.
23        """
24        return query.apply()
[5090]25
[6207]26    def searchResults(self, query):
27        """Get a set of ZODB objects conforming to a query.
28        """
29        results = self.apply(query)
30        if results is not None:
31            uidutil = getUtility(IIntIds)
32            results = ResultSet(results, uidutil)
33        return results
[5090]34
[5091]35grok.global_utility(WAeUPQuery)
[5090]36
[3521]37class StudentIndexes(grok.Indexes):
[6207]38    grok.site(University)
39    grok.name('students_catalog')
40    grok.context(IStudent)
[3521]41
[6207]42    name = grok.index.Field(attribute='name')
[3521]43
[4789]44class QueryResultItem(object):
[6207]45    grok.implements(IQueryResultItem)
46    url = None
47    title = None
48    description = None
[6116]49
[6207]50    def __init__(self, context, view):
51        self.context = context
52        self.url = view.url(context)
53        self.title = context.title
54        self.description = ''
[4789]55
56def search_context(query):
[6207]57    result = Query().searchResults(
58        Eq(('students_catalog', 'name'), query)
59        )
60    return result
Note: See TracBrowser for help on using the repository browser.