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

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

student search should work now as follows:

if All States is selected a search string must be specified.
if another review state is specified, the searchstring can be empty.
if it is not empty, both are ANDed.

File size: 4.8 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')
56err = False
57if not term and what in ('student_edit','jamb_id','name','matric_no'):
58    psm = "You must specify a search string when searching in 'All States'"
59    err = True
60elif '*' in term:
61    psm = "you cannot use the '*' alone"
62    err = True
63if err:
64    return context.students_manager_view(rendered = rend,
65                             psm = psm,
66                             #psm = "%s, %s" % (psm,ds),
67                             students = items,
68                             is_manager = is_manager,
69                             )
70with_review = state != "all"
71items = []
72res = []
73portal_type_query = {'query':['Student','StudentApplication','StudentPersonal']}
74st_queries = ('jamb_id','matric_no','name')
75onlyreview = with_review and not what
76if onlyreview:
77    res = catalog(portal_type=portal_type_query,
78                  review_state=state)
79elif what == "student_id":
80    if with_review:
81        res = catalog(portal_type='Student',
82                      id = term.strip(),
83                      review_state=state)
84    else:
85        res = catalog(portal_type='Student',
86                      id = term.strip())
87elif what in st_queries:
88    if what == "jamb_id":
89        pt = 'StudentApplication'
90        st = "%s*" % term.strip().lower()
91    elif what == "matric_no":
92        pt = 'StudentClearance'
93        st = "%s*" % term.strip().lower()
94    elif what == "name":
95        pt = portal_type_query
96        st = "%s*" % term.strip()
97    if with_review:
98        try:
99            res = catalog(portal_type=pt,SearchableText=st,
100                          review_state=state)
101        except:
102            return context.students_manager_view(rendered = rend,
103                                 psm = 'Searchstring "%s" not allowed' % term,
104                                 #psm = "%s, %s" % (psm,ds),
105                                 students = items,
106                                 is_manager = is_manager,
107                                 )
108    else:
109        try:
110            res = catalog(portal_type=pt,SearchableText=st,)
111        except:
112            return context.students_manager_view(rendered = rend,
113                                 psm = 'Searchstring "%s" not allowed' % term,
114                                 #psm = "%s, %s" % (psm,ds),
115                                 students = items,
116                                 is_manager = is_manager,
117                                 )
118           
119if res:
120    for r in res:
121        if r.portal_type in ("StudentApplication","StudentPersonal"):
122            student = r.getObject().aq_parent
123        else:
124            student = r.getObject()
125        if student not in items:
126            items.append(student)
127students = []
128if items:
129    for item in items:
130        students.append(context.getStudentInfo(item))
131return context.students_manager_view(rendered = rend,
132                             psm = "%d matching Students found" % len(items),
133                             #psm = "%s, %s" % (psm,ds),
134                             students = students,
135                             is_manager = is_manager,
136                             )
Note: See TracBrowser for help on using the repository browser.