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
RevLine 
[565]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
[584]7##parameters=
[565]8##title=
9##
10# $Id: student_edit.py 486 2006-09-06 10:09:39Z joachim $
11"""
12return Info about the current Student
13"""
[589]14#from Products.ZCTextIndex.QueryParser import ParseError,QueryError
[565]15request = context.REQUEST
16form = request.form
17fget = form.get
[572]18info = {}
[565]19wf = context.portal_workflow
[572]20catalog = context.portal_catalog
21student_wf_states = wf.waeup_student_wf.states.keys()
22info['wf_states'] = student_wf_states
23info['wf_states'][0] = " ----- "
[565]24mtool = context.portal_membership
25member = mtool.getAuthenticatedMember()
[584]26lt = context.portal_layouts
27pr = context.portal_registration
[565]28path_info = request.get('PATH_INFO').split('/')
29roles = member.getRoles()
[584]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 ',
[587]35        'search_string': ''
[584]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')
[589]56err = False
[599]57with_review = state != "all"
58if not term and not with_review:
[596]59    psm = "You must specify a search string when searching in 'All States'"
[589]60    err = True
61elif '*' in term:
[596]62    psm = "you cannot use the '*' alone"
[589]63    err = True
64if err:
[587]65    return context.students_manager_view(rendered = rend,
[589]66                             psm = psm,
[587]67                             #psm = "%s, %s" % (psm,ds),
68                             students = items,
69                             is_manager = is_manager,
70                             )
[596]71with_review = state != "all"
[572]72items = []
73res = []
74portal_type_query = {'query':['Student','StudentApplication','StudentPersonal']}
[589]75st_queries = ('jamb_id','matric_no','name')
[599]76onlyreview = with_review and not term
[572]77if onlyreview:
78    res = catalog(portal_type=portal_type_query,
79                  review_state=state)
[584]80elif what == "student_id":
[596]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())
[589]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()
[596]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                                 )
[589]119           
[572]120if res:
121    for r in res:
122        if r.portal_type in ("StudentApplication","StudentPersonal"):
[589]123            student = r.getObject().aq_parent
[572]124        else:
[589]125            student = r.getObject()
126        if student not in items:
127            items.append(student)
[584]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.