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

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

add and delete for student_study_level and student_course_result

File size: 6.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"""
14try:
15    from Products.AdvancedQuery import Eq, Between, Le
16    evalAdvancedQuery = context.portal_catalog.evalAdvancedQuery
17except:
18    evalAdvancedQuery = None
19   
20request = context.REQUEST
21form = request.form
22fget = form.get
23info = {}
24wf = context.portal_workflow
25catalog = context.portal_catalog
26#student_wf_states = wf.waeup_student_wf.states.keys()
27#info['wf_states'] = student_wf_states
28#info['wf_states'][0] = " ----- "
29lt = context.portal_layouts
30pr = context.portal_registration
31path_info = request.get('PATH_INFO').split('/')
32is_manager = context.isManager
33validate = request.has_key("cpsdocument_edit_button")
34items = []
35default = {'search_mode': 'name',
36        'review_state': 'all',
37        'search_string': ''
38        }
39
40rend,psm,ds = lt.renderLayout(layout_id= 'student_search',
41                      schema_id= 'student_search',
42                      context=context,
43                      mapping=validate and request,
44                      ob=default,
45                      layout_mode='edit',
46                      formaction="searchStudents"
47                      )
48if psm == '':
49    return context.students_manager_view(rendered = rend,
50                             psm = psm,
51                             #psm = "%s, %s" % (psm,ds),
52                             students = items,
53                             is_manager = is_manager,
54                             )
55what = ds.get('search_mode')
56state = ds.get('review_state')
57st = term = ds.get('search_string')
58err = False
59with_review = state != "all"
60onlyreview = with_review and not term
61with_level_results = state.startswith("category") or\
62                     state in ('content_addable',) and\
63                     evalAdvancedQuery is not None
64bools = "with_review = %s<br\> onlyreview = %s<br\> with_level_results = %s" % (with_review,onlyreview,with_level_results)
65if not term and not with_review:
66    psm = "You must specify a search string when searching 'all states'."
67    err = True
68elif '*' in term:
69    psm = "you cannot use the '*' alone"
70    err = True
71if err:
72    return context.students_manager_view(rendered = rend,
73                             psm = psm,
74                             #psm = "%s, %s" % (psm,ds),
75                             students = items,
76                             is_manager = is_manager,
77                             )
78items = []
79res = []
80portal_type_query = {'query':['Student','StudentApplication','StudentPersonal']}
81st_queries = ('jamb_reg_no','matric_no','name')
82query_step = 0
83if onlyreview and not with_level_results:
84    query_step = 1
85    query =  Eq('portal_type','Student') & Eq('review_state',state)
86    res = evalAdvancedQuery(query)
87##    res = catalog(portal_type='Student',
88##                  review_state=state)
89elif onlyreview and with_level_results:
90    query_step = 2
91    query =  (Eq('portal_type','StudentStudyLevel') |
92             Eq('portal_type','StudentStudyCourse')) & Eq('review_state',state)
93    res = evalAdvancedQuery(query)
94elif what == "student_id":
95    if with_review:
96        query_step = 3
97        res = catalog(portal_type='Student',
98                      id = term.strip(),
99                      review_state=state)
100    else:
101        query_step = 4
102        res = catalog(portal_type='Student',
103                      id = term.strip())
104elif what in st_queries and not with_level_results:
105    if what == "jamb_reg_no":
106        query_step = 5
107        pt = 'StudentApplication'
108        st = "%s*" % term.strip().lower()
109    elif what == "matric_no":
110        query_step = 6
111        pt = 'StudentClearance'
112        st = "%s*" % term.strip().lower()
113    elif what == "name":
114        query_step = 7
115        pt = portal_type_query
116        st = "%s*" % term.strip()
117    try:
118        res = catalog(portal_type=pt,SearchableText=st)
119    except:
120        return context.students_manager_view(rendered = rend,
121                             psm = 'Search string "%s" not allowed.' % term,
122                             #psm = "%s, %s" % (psm,ds),
123                             students = items,
124                             is_manager = is_manager,
125                             )
126elif what in st_queries and with_level_results and evalAdvancedQuery:
127    if what == "jamb_reg_no":
128        query_step = 8
129        pt = 'StudentApplication'
130        st = "%s*" % term.strip().lower()
131    elif what == "matric_no":
132        query_step = 9
133        pt = 'StudentClearance'
134        st = "%s*" % term.strip().lower()
135    elif what == "name":
136        query_step = 10
137        pt = portal_type_query
138        st = "%s*" % term.strip()
139    query = Eq('portal_type',pt) & Eq('SearchableText',"%s*" % term.strip().lower())\
140                | ((Eq('portal_type','StudentStudyLevel') |
141                   Eq('portal_type','StudentStudyCourse')) & Eq('review_state',state))
142    try:
143        res = evalAdvancedQuery(query)
144    except:
145        return context.students_manager_view(rendered = rend,
146                             psm = 'Advanced Query failed' % term,
147                             #psm = "%s, %s" % (psm,ds),
148                             students = items,
149                             is_manager = is_manager,
150                             )
151students = []
152raw_res = len(res)
153if res:
154    for r in res:
155        if r.portal_type in ("StudentApplication","StudentPersonal","StudentStudyCourse",):
156            student = r.getObject().aq_parent
157        elif r.portal_type in ("StudentStudyLevel",):
158            student = r.getObject().aq_parent.aq_parent
159##            pp = '/'.join(r.getPath().split('/')[:-1])
160##            student_cat = catalog(pathindex=pp,portal_type='Student')[0]
161##            student_rs = student_cat.review_state
162##            student = student_cat.getObject()
163        else:
164            student = r.getObject()
165        student_rs = wf.getInfoFor(student,'review_state','keiner')
166        if (with_review and student_rs != state and not with_level_results) or student in items:
167            continue
168        items.append(student)
169if items:
170    for item in items:
171        students.append(context.getStudentInfo(item))
172    return context.students_manager_view(rendered = rend,
173                             psm = "%d matching Students found QS = %s" % (len(items),query_step),
174                             students = students,
175                             is_manager = is_manager,
176                             )
177return context.students_manager_view(rendered = rend,
178                             psm = """Step: %s found: %s Your search for "%s" in %s with state %s failed.<br\>%s""" % (query_step,raw_res,st,what,state,bools),
179                             students = students,
180                             is_manager = is_manager,
181                             )
Note: See TracBrowser for help on using the repository browser.