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,In |
---|
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 | student_subobjects = ("StudentApplication", |
---|
24 | "StudentPersonal", |
---|
25 | "StudentStudyCourse", |
---|
26 | "StudentAccommodation", |
---|
27 | "StudentStudyLevel",) |
---|
28 | info = {} |
---|
29 | items = [] |
---|
30 | wf = context.portal_workflow |
---|
31 | catalog = context.portal_catalog |
---|
32 | #student_wf_states = wf.waeup_student_wf.states.keys() |
---|
33 | #info['wf_states'] = student_wf_states |
---|
34 | #info['wf_states'][0] = " ----- " |
---|
35 | lt = context.portal_layouts |
---|
36 | pr = context.portal_registration |
---|
37 | path_info = request.get('PATH_INFO').split('/') |
---|
38 | is_manager = context.isManager |
---|
39 | validate = request.has_key("cpsdocument_edit_button") |
---|
40 | default = {'search_mode': 'name', |
---|
41 | 'review_state': 'all', |
---|
42 | 'search_string': '' |
---|
43 | } |
---|
44 | |
---|
45 | rend,psm,ds = lt.renderLayout(layout_id= 'student_search', |
---|
46 | schema_id= 'student_search', |
---|
47 | context=context, |
---|
48 | mapping=validate and request, |
---|
49 | ob=default, |
---|
50 | layout_mode='edit', |
---|
51 | formaction="searchStudents" |
---|
52 | ) |
---|
53 | if psm == '': |
---|
54 | return context.students_manager_view(rendered = rend, |
---|
55 | psm = psm, |
---|
56 | #psm = "%s, %s" % (psm,ds), |
---|
57 | students = items, |
---|
58 | is_manager = is_manager, |
---|
59 | ) |
---|
60 | what = ds.get('search_mode') |
---|
61 | state = ds.get('review_state') |
---|
62 | st = term = ds.get('search_string') |
---|
63 | err = False |
---|
64 | with_review = state != "all" |
---|
65 | only_review = with_review and not term |
---|
66 | ##with_level_results = state.startswith("category") or\ |
---|
67 | ## state in ('content_addable',) and\ |
---|
68 | ## evalAdvancedQuery is not None |
---|
69 | bools = "with_review = %s<br\> only_review = %s<br\>" % (with_review,only_review) |
---|
70 | if not term and not with_review: |
---|
71 | psm = "You must specify a search string when searching 'all states'." |
---|
72 | err = True |
---|
73 | elif '*' in term: |
---|
74 | psm = "you cannot use the '*' alone" |
---|
75 | err = True |
---|
76 | if err: |
---|
77 | return context.students_manager_view(rendered = rend, |
---|
78 | psm = psm, |
---|
79 | #psm = "%s, %s" % (psm,ds), |
---|
80 | students = items, |
---|
81 | is_manager = is_manager, |
---|
82 | ) |
---|
83 | items = [] |
---|
84 | res = [] |
---|
85 | portal_type_query = {'query':['Student','StudentApplication','StudentPersonal']} |
---|
86 | st_queries = ('jamb_reg_no','matric_no','name') |
---|
87 | query_step = 0 |
---|
88 | review_res = None |
---|
89 | query = None |
---|
90 | if len(term) > 0: |
---|
91 | if what == "student_id": |
---|
92 | query_step = 1 |
---|
93 | query = Eq('portal_type','Student') & Eq('id', term.strip()) |
---|
94 | elif what in st_queries: |
---|
95 | if what == "jamb_reg_no": |
---|
96 | query_step = 2 |
---|
97 | pt = ('StudentApplication',) |
---|
98 | st = "%s" % term.strip().lower() |
---|
99 | elif what == "matric_no": |
---|
100 | query_step = 3 |
---|
101 | pt = ('StudentClearance',) |
---|
102 | st = "%s" % term.strip().lower() |
---|
103 | elif what == "name": |
---|
104 | query_step = 4 |
---|
105 | pt = ('StudentPersonal') |
---|
106 | st = "%s" % term.strip() |
---|
107 | query = In('portal_type',pt) & Eq('SearchableText',"%s*" % term.strip()) |
---|
108 | res = evalAdvancedQuery(query) |
---|
109 | if with_review: |
---|
110 | query_step += 10 |
---|
111 | review_res = evalAdvancedQuery(In('portal_type',student_subobjects) & Eq('review_state',state)) |
---|
112 | search_set = [] |
---|
113 | if res: |
---|
114 | for r in res: |
---|
115 | if r.portal_type in ("StudentStudyLevel",): |
---|
116 | student = r.getObject().aq_parent.aq_parent |
---|
117 | elif r.portal_type in student_subobjects: |
---|
118 | student = r.getObject().aq_parent |
---|
119 | else: |
---|
120 | student = r.getObject() |
---|
121 | search_set.append(student) |
---|
122 | review_set = [] |
---|
123 | if review_res: |
---|
124 | for r in review_res: |
---|
125 | if r.portal_type in ("StudentStudyLevel",): |
---|
126 | student = r.getObject().aq_parent.aq_parent |
---|
127 | elif r.portal_type in student_subobjects: |
---|
128 | student = r.getObject().aq_parent |
---|
129 | else: |
---|
130 | student = r.getObject() |
---|
131 | review_set.append(student) |
---|
132 | all = [] |
---|
133 | if only_review: |
---|
134 | all = review_set |
---|
135 | elif with_review: |
---|
136 | for i in search_set: |
---|
137 | if i in review_set: |
---|
138 | all.append(i) |
---|
139 | else: |
---|
140 | all = search_set |
---|
141 | for a in all: |
---|
142 | if a in items: |
---|
143 | continue |
---|
144 | items.append(a) |
---|
145 | students = [] |
---|
146 | if items: |
---|
147 | for item in items: |
---|
148 | info = context.getStudentInfo(item) |
---|
149 | students.append(info) |
---|
150 | return context.students_manager_view(rendered = rend, |
---|
151 | psm = "%d,%d matching Students found QS = %s" %\ |
---|
152 | (len(review_set),len(search_set),query_step), |
---|
153 | #psm = "%d found QS = %s items: %s" % (len(items),query_step,items), |
---|
154 | students = students, |
---|
155 | is_manager = is_manager, |
---|
156 | ) |
---|
157 | return context.students_manager_view(rendered = rend, |
---|
158 | psm = """Step: %s found: %s Your search for "%s" in %s with state %s failed.<br\>%s""" % (query_step,len(items),st,what,state,bools), |
---|
159 | students = students, |
---|
160 | is_manager = is_manager, |
---|
161 | ) |
---|