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 | if not term and what in ('student_edit','jamb_id','name','matric_no'): |
---|
58 | psm = "You must specify a search string when searching in 'All States'" |
---|
59 | err = True |
---|
60 | elif '*' in term: |
---|
61 | psm = "you cannot use the '*' alone" |
---|
62 | err = True |
---|
63 | if err: |
---|
64 | return context.students_manager_view(rendered = rend, |
---|
65 | psm = psm, |
---|
66 | #psm = "%s, %s" % (psm,ds), |
---|
67 | students = items, |
---|
68 | is_manager = is_manager, |
---|
69 | ) |
---|
70 | with_review = state != "all" |
---|
71 | items = [] |
---|
72 | res = [] |
---|
73 | portal_type_query = {'query':['Student','StudentApplication','StudentPersonal']} |
---|
74 | st_queries = ('jamb_id','matric_no','name') |
---|
75 | onlyreview = with_review and not what |
---|
76 | if onlyreview: |
---|
77 | res = catalog(portal_type=portal_type_query, |
---|
78 | review_state=state) |
---|
79 | elif what == "student_id": |
---|
80 | if with_review: |
---|
81 | res = catalog(portal_type='Student', |
---|
82 | id = term.strip(), |
---|
83 | review_state=state) |
---|
84 | else: |
---|
85 | res = catalog(portal_type='Student', |
---|
86 | id = term.strip()) |
---|
87 | elif what in st_queries: |
---|
88 | if what == "jamb_id": |
---|
89 | pt = 'StudentApplication' |
---|
90 | st = "%s*" % term.strip().lower() |
---|
91 | elif what == "matric_no": |
---|
92 | pt = 'StudentClearance' |
---|
93 | st = "%s*" % term.strip().lower() |
---|
94 | elif what == "name": |
---|
95 | pt = portal_type_query |
---|
96 | st = "%s*" % term.strip() |
---|
97 | if with_review: |
---|
98 | try: |
---|
99 | res = catalog(portal_type=pt,SearchableText=st, |
---|
100 | review_state=state) |
---|
101 | except: |
---|
102 | return context.students_manager_view(rendered = rend, |
---|
103 | psm = 'Searchstring "%s" not allowed' % term, |
---|
104 | #psm = "%s, %s" % (psm,ds), |
---|
105 | students = items, |
---|
106 | is_manager = is_manager, |
---|
107 | ) |
---|
108 | else: |
---|
109 | try: |
---|
110 | res = catalog(portal_type=pt,SearchableText=st,) |
---|
111 | except: |
---|
112 | return context.students_manager_view(rendered = rend, |
---|
113 | psm = 'Searchstring "%s" not allowed' % term, |
---|
114 | #psm = "%s, %s" % (psm,ds), |
---|
115 | students = items, |
---|
116 | is_manager = is_manager, |
---|
117 | ) |
---|
118 | |
---|
119 | if res: |
---|
120 | for r in res: |
---|
121 | if r.portal_type in ("StudentApplication","StudentPersonal"): |
---|
122 | student = r.getObject().aq_parent |
---|
123 | else: |
---|
124 | student = r.getObject() |
---|
125 | if student not in items: |
---|
126 | items.append(student) |
---|
127 | students = [] |
---|
128 | if items: |
---|
129 | for item in items: |
---|
130 | students.append(context.getStudentInfo(item)) |
---|
131 | return context.students_manager_view(rendered = rend, |
---|
132 | psm = "%d matching Students found" % len(items), |
---|
133 | #psm = "%s, %s" % (psm,ds), |
---|
134 | students = students, |
---|
135 | is_manager = is_manager, |
---|
136 | ) |
---|