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

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

some fixes it should now work as documented

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