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

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

Add students_catalog and search facilities.

  • Property svn:keywords set to Id
File size: 1.6 KB
Line 
1"""Cataloging and searching components for students.
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.students.interfaces import IStudent
10
11class StudentIndexes(grok.Indexes):
12    """A catalog for students.
13    """
14    grok.site(IUniversity)
15    grok.name('students_catalog')
16    grok.context(IStudent)
17
18    student_id = index.Field(attribute='student_id')
19    name = index.Text(attribute='name')
20    #history = index.Text(attribute='history')
21    #state = index.Field(attribute='state')
22
23class StudentQueryResultItem(object):
24    grok.implements(IQueryResultItem)
25
26    title = u'Student Query Item'
27    description = u'Some students found in a search'
28
29    def __init__(self, context, view):
30        self.context = context
31        self.url = view.url(context)
32        self.student_id = context.student_id
33        self.name = context.name
34        #self.history = context.history
35        #self.state = context.state
36
37def search(query=None, searchtype=None, view=None):
38    hitlist = []
39    #if not query:
40    #    view.flash('Empty search string.')
41    #    return
42    if searchtype in ('history','name'):
43        results = Query().searchResults(
44            Text(('students_catalog', searchtype), query))
45    else:
46        results = Query().searchResults(
47            Eq(('students_catalog', searchtype), query))
48    for result in results:
49        hitlist.append(StudentQueryResultItem(result, view=view))
50    return hitlist
Note: See TracBrowser for help on using the repository browser.