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

Last change on this file since 6551 was 6551, checked in by uli, 13 years ago

Remove strange exception catcher. I have no clue how to provoke that
kind of exception (ParseError?) while there are tons of other
(uncatched) exceptions that can occur with the search function.

File size: 1.8 KB
Line 
1"""Cataloging and searching components for access codes.
2"""
3import grok
4from grok import index
5from hurry.query import Eq, Text
6from hurry.query.query import Query
7from zope.index.text.parsetree import ParseError
8from waeup.sirp.interfaces import IUniversity, IQueryResultItem
9from waeup.sirp.accesscodes.interfaces import IAccessCode
10
11class AccessCodeIndexes(grok.Indexes):
12    """A catalog for access codes.
13    """
14    grok.site(IUniversity)
15    grok.name('accesscodes_catalog')
16    grok.context(IAccessCode)
17
18    code = index.Field(attribute='representation')
19    history = index.Text(attribute='history')
20    batch_serial = index.Field(attribute='batch_serial')
21    state = index.Field(attribute='state')
22
23class AccessCodeQueryResultItem(object):
24    grok.implements(IQueryResultItem)
25
26    title = u'Access Code Query Item'
27    description = u'Some access code found in a search'
28
29    def __init__(self, context, view):
30        self.context = context
31        self.url = view.url(context)
32        self.code = context.representation
33        self.history = context.history
34        self.state = context.state
35        self.batch_serial = context.batch_serial
36
37def search(query=None, searchtype=None, view=None):
38    if not query:
39        view.flash('Empty search string.')
40        return
41    hitlist = []
42    if searchtype == 'history':
43        results = Query().searchResults(
44            Text(('accesscodes_catalog', searchtype), query))
45    elif searchtype == 'batch_serial':
46        results = Query().searchResults(
47            Eq(('accesscodes_catalog', searchtype), int(query)))
48    else:
49        results = Query().searchResults(
50            Eq(('accesscodes_catalog', searchtype), query))
51    for result in results:
52        hitlist.append(AccessCodeQueryResultItem(result, view=view))
53    return hitlist
Note: See TracBrowser for help on using the repository browser.