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

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

Add reg_number attribute which is needed for first-time login (admission checking).

  • Property svn:keywords set to Id
File size: 1.9 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    reg_number = index.Field(attribute='reg_number')
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.reg_number = context.reg_number
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 ('name',):
43        results = Query().searchResults(
44            Text(('students_catalog', searchtype), query))
45    else:
46        # Temporary solution to display all students added
47        if query == '*':
48            from zope.component import queryUtility
49            from zope.catalog.interfaces import ICatalog
50            cat = queryUtility(ICatalog, name='students_catalog')
51            results = cat.searchResults(student_id=(None, None))
52        else:
53            results = Query().searchResults(
54                Eq(('students_catalog', searchtype), query))
55    for result in results:
56        hitlist.append(StudentQueryResultItem(result, view=view))
57    return hitlist
Note: See TracBrowser for help on using the repository browser.