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

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

Show owner on search page.

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.owner = context.owner
36        self.batch_serial = context.batch_serial
37
38def search(query=None, searchtype=None, view=None):
39    if not query:
40        view.flash('Empty search string.')
41        return
42    hitlist = []
43    if searchtype == 'history':
44        results = Query().searchResults(
45            Text(('accesscodes_catalog', searchtype), query))
46    elif searchtype == 'batch_serial':
47        results = Query().searchResults(
48            Eq(('accesscodes_catalog', searchtype), int(query)))
49    else:
50        results = Query().searchResults(
51            Eq(('accesscodes_catalog', searchtype), query))
52    for result in results:
53        hitlist.append(AccessCodeQueryResultItem(result, view=view))
54    return hitlist
Note: See TracBrowser for help on using the repository browser.