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

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

Replace properties 'used' and 'disabled' by 'status'.

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    status = grok.index.Field(attribute='status')
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.status = context.status
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.