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 | #from Products.ZCTextIndex.QueryParser import ParseError,QueryError |
---|
15 | request = context.REQUEST |
---|
16 | form = request.form |
---|
17 | fget = form.get |
---|
18 | info = {} |
---|
19 | wf = context.portal_workflow |
---|
20 | catalog = 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] = " ----- " |
---|
24 | mtool = context.portal_membership |
---|
25 | member = mtool.getAuthenticatedMember() |
---|
26 | lt = context.portal_layouts |
---|
27 | pr = context.portal_registration |
---|
28 | path_info = request.get('PATH_INFO').split('/') |
---|
29 | roles = member.getRoles() |
---|
30 | is_manager = 'Manager' in roles or 'SectionManager' in roles |
---|
31 | validate = request.has_key("cpsdocument_edit_button") |
---|
32 | items = [] |
---|
33 | default = {'search_mode': 'name', |
---|
34 | 'review_state': 'admission_applied ', |
---|
35 | 'search_string': '' |
---|
36 | } |
---|
37 | |
---|
38 | rend,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 | ) |
---|
46 | if 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 | ) |
---|
53 | what = ds.get('search_mode') |
---|
54 | state = ds.get('review_state') |
---|
55 | term = ds.get('search_string') |
---|
56 | err = False |
---|
57 | with_review = state != "all" |
---|
58 | if not term and not with_review: |
---|
59 | psm = "You must specify a search string when searching in 'All States'" |
---|
60 | err = True |
---|
61 | elif '*' in term: |
---|
62 | psm = "you cannot use the '*' alone" |
---|
63 | err = True |
---|
64 | if err: |
---|
65 | return context.students_manager_view(rendered = rend, |
---|
66 | psm = psm, |
---|
67 | #psm = "%s, %s" % (psm,ds), |
---|
68 | students = items, |
---|
69 | is_manager = is_manager, |
---|
70 | ) |
---|
71 | with_review = state != "all" |
---|
72 | items = [] |
---|
73 | res = [] |
---|
74 | portal_type_query = {'query':['Student','StudentApplication','StudentPersonal']} |
---|
75 | st_queries = ('jamb_id','matric_no','name') |
---|
76 | onlyreview = with_review and not term |
---|
77 | if onlyreview: |
---|
78 | res = catalog(portal_type=portal_type_query, |
---|
79 | review_state=state) |
---|
80 | elif what == "student_id": |
---|
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()) |
---|
88 | elif 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() |
---|
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 | ) |
---|
119 | |
---|
120 | if res: |
---|
121 | for r in res: |
---|
122 | if r.portal_type in ("StudentApplication","StudentPersonal"): |
---|
123 | student = r.getObject().aq_parent |
---|
124 | else: |
---|
125 | student = r.getObject() |
---|
126 | if student not in items: |
---|
127 | items.append(student) |
---|
128 | students = [] |
---|
129 | if items: |
---|
130 | for item in items: |
---|
131 | students.append(context.getStudentInfo(item)) |
---|
132 | return 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 | ) |
---|