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

Last change on this file since 688 was 680, checked in by Henrik Bettermann, 18 years ago

accommodation and application methods are now completely equal

File size: 4.7 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
21#student_wf_states = wf.waeup_student_wf.states.keys()
22#info['wf_states'] = student_wf_states
23#info['wf_states'][0] = " ----- "
24lt = context.portal_layouts
25pr = context.portal_registration
26path_info = request.get('PATH_INFO').split('/')
27is_manager = context.isManager
28validate = request.has_key("cpsdocument_edit_button")
29items = []
30default = {'search_mode': 'name',
31        'review_state': 'all',
32        'search_string': ''
33        }
34
35rend,psm,ds = lt.renderLayout(layout_id= 'student_search',
36                      schema_id= 'student_search',
37                      context=context,
38                      mapping=validate and request,
39                      ob=default,
40                      layout_mode='edit',
41                      formaction="searchStudents"
42                      )
43if psm == '':
44    return context.students_manager_view(rendered = rend,
45                             psm = psm,
46                             #psm = "%s, %s" % (psm,ds),
47                             students = items,
48                             is_manager = is_manager,
49                             )
50what = ds.get('search_mode')
51state = ds.get('review_state')
52st = term = ds.get('search_string')
53err = False
54with_review = state != "all"
55if not term and not with_review:
56    psm = "You must specify a search string when searching 'all states'."
57    err = True
58elif '*' in term:
59    psm = "you cannot use the '*' alone"
60    err = True
61if err:
62    return context.students_manager_view(rendered = rend,
63                             psm = psm,
64                             #psm = "%s, %s" % (psm,ds),
65                             students = items,
66                             is_manager = is_manager,
67                             )
68with_review = state != "all"
69items = []
70res = []
71portal_type_query = {'query':['Student','StudentApplication','StudentPersonal']}
72st_queries = ('jamb_reg_no','matric_no','name')
73onlyreview = with_review and not term
74if onlyreview:
75    res = catalog(portal_type='Student',
76                  review_state=state)
77elif what == "student_id":
78    if with_review:
79        res = catalog(portal_type='Student',
80                      id = term.strip(),
81                      review_state=state)
82    else:
83        res = catalog(portal_type='Student',
84                      id = term.strip())
85elif what in st_queries:
86    if what == "jamb_reg_no":
87        pt = 'StudentApplication'
88        st = "%s*" % term.strip().lower()
89    elif what == "matric_no":
90        pt = 'StudentClearance'
91        st = "%s*" % term.strip().lower()
92    elif what == "name":
93        pt = portal_type_query
94        st = "%s*" % term.strip()
95    try:
96        res = catalog(portal_type=pt,SearchableText=st)
97    except:
98        return context.students_manager_view(rendered = rend,
99                             psm = 'Search string "%s" not allowed.' % term,
100                             #psm = "%s, %s" % (psm,ds),
101                             students = items,
102                             is_manager = is_manager,
103                             )
104students = []
105if res:
106    for r in res:
107        if r.portal_type in ("StudentApplication","StudentPersonal"):
108            student = r.getObject().aq_parent
109##            pp = '/'.join(r.getPath().split('/')[:-1])
110##            student_cat = catalog(pathindex=pp,portal_type='Student')[0]
111##            student_rs = student_cat.review_state
112##            student = student_cat.getObject()
113        else:
114            student = r.getObject()
115        student_rs = wf.getInfoFor(student,'review_state','keiner')
116        if (with_review and student_rs != state) or student in items:
117            continue
118        items.append(student)
119if items:
120    for item in items:
121        students.append(context.getStudentInfo(item))
122    return context.students_manager_view(rendered = rend,
123                             psm = "%d matching Students found" % len(items),
124                             students = students,
125                             is_manager = is_manager,
126                             )
127return context.students_manager_view(rendered = rend,
128                             psm = """Your search for "%s" in %s with state %s failed.""" % (st,what,state),
129                             students = students,
130                             is_manager = is_manager,
131                             )
Note: See TracBrowser for help on using the repository browser.