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 | """ |
---|
12 | return Info about the current Student |
---|
13 | """ |
---|
14 | try: |
---|
15 | from Products.AdvancedQuery import Eq, Between, Le |
---|
16 | evalAdvancedQuery = context.portal_catalog.evalAdvancedQuery |
---|
17 | except: |
---|
18 | evalAdvancedQuery = None |
---|
19 | |
---|
20 | request = context.REQUEST |
---|
21 | form = request.form |
---|
22 | fget = form.get |
---|
23 | info = {} |
---|
24 | wf = context.portal_workflow |
---|
25 | catalog = 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] = " ----- " |
---|
29 | lt = context.portal_layouts |
---|
30 | pr = context.portal_registration |
---|
31 | path_info = request.get('PATH_INFO').split('/') |
---|
32 | is_manager = context.isManager |
---|
33 | validate = request.has_key("cpsdocument_edit_button") |
---|
34 | items = [] |
---|
35 | default = {'search_mode': 'name', |
---|
36 | 'review_state': 'all', |
---|
37 | 'search_string': '' |
---|
38 | } |
---|
39 | |
---|
40 | rend,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 | ) |
---|
48 | if 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 | ) |
---|
55 | what = ds.get('search_mode') |
---|
56 | state = ds.get('review_state') |
---|
57 | st = term = ds.get('search_string') |
---|
58 | err = False |
---|
59 | with_review = state != "all" |
---|
60 | onlyreview = with_review and not term |
---|
61 | with_level_results = state.startswith("category") or\ |
---|
62 | state in ('content_addable',) and\ |
---|
63 | evalAdvancedQuery is not None |
---|
64 | bools = "with_review = %s<br\> onlyreview = %s<br\> with_level_results = %s" % (with_review,onlyreview,with_level_results) |
---|
65 | if not term and not with_review: |
---|
66 | psm = "You must specify a search string when searching 'all states'." |
---|
67 | err = True |
---|
68 | elif '*' in term: |
---|
69 | psm = "you cannot use the '*' alone" |
---|
70 | err = True |
---|
71 | if 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 | ) |
---|
78 | items = [] |
---|
79 | res = [] |
---|
80 | portal_type_query = {'query':['Student','StudentApplication','StudentPersonal']} |
---|
81 | st_queries = ('jamb_reg_no','matric_no','name') |
---|
82 | query_step = 0 |
---|
83 | if 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) |
---|
89 | elif 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) |
---|
94 | elif 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()) |
---|
104 | elif 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 | ) |
---|
126 | elif 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 | ) |
---|
151 | students = [] |
---|
152 | raw_res = len(res) |
---|
153 | if 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) |
---|
169 | if 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 | ) |
---|
177 | return 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 | ) |
---|