source: WAeUP_SRP/trunk/skins/waeup_student/searchStudents.py @ 594

Last change on this file since 594 was 589, checked in by joachim, 18 years ago

studentSearch enhenced

File size: 4.1 KB
Line 
1## Script (Python) "cpsdocument_edit"
2##bind container=container
3##bind context=context
4##bind namespace=
5##bind script=script
6##bind subpath=traverse_subpath
7##parameters=
8##title=
9##
10# $Id: student_edit.py 486 2006-09-06 10:09:39Z joachim $
11"""
12return Info about the current Student
13"""
14#from Products.ZCTextIndex.QueryParser import ParseError,QueryError
15request = context.REQUEST
16form = request.form
17fget = form.get
18info = {}
19wf = context.portal_workflow
20catalog = context.portal_catalog
21student_wf_states = wf.waeup_student_wf.states.keys()
22info['wf_states'] = student_wf_states
23info['wf_states'][0] = " ----- "
24mtool = context.portal_membership
25member = mtool.getAuthenticatedMember()
26lt = context.portal_layouts
27pr = context.portal_registration
28path_info = request.get('PATH_INFO').split('/')
29roles = member.getRoles()
30is_manager = 'Manager' in roles or 'SectionManager' in roles
31validate = request.has_key("cpsdocument_edit_button")
32items = []
33default = {'search_mode': 'name',
34        'review_state': 'admission_applied ',
35        'search_string': ''
36        }
37       
38rend,psm,ds = lt.renderLayout(layout_id= 'student_search',
39                      schema_id= 'student_search',
40                      context=context,
41                      mapping=validate and request,
42                      ob=default,
43                      layout_mode='edit',
44                      formaction="searchStudents"
45                      )
46if psm == '':
47    return context.students_manager_view(rendered = rend,
48                             psm = psm,
49                             #psm = "%s, %s" % (psm,ds),
50                             students = items,
51                             is_manager = is_manager,
52                             )
53what = ds.get('search_mode')
54state = ds.get('review_state')
55term = ds.get('search_string')
56if state == " ----- ":
57    state = ''
58err = False
59if not term and what in ('student_edit','jamb_id','name','matric_no'):
60    psm = "You must specify a search string"
61    err = True
62elif '*' in term:
63    psm = "You cannot use '*'"
64    err = True
65if err:
66    return context.students_manager_view(rendered = rend,
67                             psm = psm,
68                             #psm = "%s, %s" % (psm,ds),
69                             students = items,
70                             is_manager = is_manager,
71                             )
72onlyreview = state and what == "review_state"
73items = []
74res = []
75portal_type_query = {'query':['Student','StudentApplication','StudentPersonal']}
76st_queries = ('jamb_id','matric_no','name')
77if onlyreview:
78    res = catalog(portal_type=portal_type_query,
79                  review_state=state)
80elif what == "student_id":
81    res = catalog(portal_type='Student',
82                  id = term.strip())
83elif what in st_queries:
84    if what == "jamb_id":
85        pt = 'StudentApplication'
86        st = "%s*" % term.strip().lower()
87    elif what == "matric_no":
88        pt = 'StudentClearance'
89        st = "%s*" % term.strip().lower()
90    elif what == "name":
91        pt = portal_type_query
92        st = "%s*" % term.strip()
93    try:
94        res = catalog(portal_type=pt,SearchableText=st,)
95    except:
96        return context.students_manager_view(rendered = rend,
97                             psm = 'Searchstring "%s" not allowed' % term,
98                             #psm = "%s, %s" % (psm,ds),
99                             students = items,
100                             is_manager = is_manager,
101                             )
102           
103if res:
104    for r in res:
105        if r.portal_type in ("StudentApplication","StudentPersonal"):
106            student = r.getObject().aq_parent
107        else:
108            student = r.getObject()
109        if student not in items:
110            items.append(student)
111students = []
112if items:
113    for item in items:
114        students.append(context.getStudentInfo(item))
115return context.students_manager_view(rendered = rend,
116                             psm = "%d matching Students found" % len(items),
117                             #psm = "%s, %s" % (psm,ds),
118                             students = students,
119                             is_manager = is_manager,
120                             )
Note: See TracBrowser for help on using the repository browser.