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

Last change on this file since 6534 was 6470, checked in by Henrik Bettermann, 14 years ago

It should always be workflow state not status. My mistake.

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