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=student=None |
---|
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 | request = context.REQUEST |
---|
15 | form = request.form |
---|
16 | fget = form.get |
---|
17 | wf = context.portal_workflow |
---|
18 | mtool = context.portal_membership |
---|
19 | member = mtool.getAuthenticatedMember() |
---|
20 | path_info = request.get('PATH_INFO').split('/') |
---|
21 | roles = member.getRoles() |
---|
22 | |
---|
23 | info = {} |
---|
24 | info['is_manager'] = context.isManager() |
---|
25 | info['is_student'] = context.isStudent() |
---|
26 | member_id = str(member) |
---|
27 | if student is None: |
---|
28 | if context.isManager() and 'students' in path_info: |
---|
29 | student_id = path_info[path_info.index('students')+1] |
---|
30 | else: |
---|
31 | student_id = member_id |
---|
32 | else: |
---|
33 | student_id = student.getId() |
---|
34 | res = context.portal_catalog(id = student_id,portal_type='Student') |
---|
35 | if not res:# or len(res) > 1: |
---|
36 | return None |
---|
37 | brain = res[-1] |
---|
38 | student = brain.getObject() |
---|
39 | student_path = brain.getPath() |
---|
40 | info['review_state'] = wf.getInfoFor(student,'review_state',None) |
---|
41 | info['student'] = student |
---|
42 | info['id'] = student.getId() |
---|
43 | info['url'] = student.absolute_url() |
---|
44 | info['student_doc'] = student.getContent() |
---|
45 | info['app'] = student.application |
---|
46 | info['app_doc'] = student.application.getContent() |
---|
47 | info['per'] = student.personal |
---|
48 | info['per_doc'] = student.personal.getContent() |
---|
49 | info['sex'] = 'male' |
---|
50 | if info['per_doc'].sex: |
---|
51 | info['sex'] = 'female' |
---|
52 | res = context.portal_catalog(container_path=student_path, |
---|
53 | portal_type='StudentAccommodation') |
---|
54 | if res: |
---|
55 | acco = res[0].getObject() |
---|
56 | info['acco'] = acco |
---|
57 | info['acco_doc'] = acco.getContent() |
---|
58 | info['acco_review_state'] = wf.getInfoFor(acco,'review_state',None) |
---|
59 | else: |
---|
60 | info['acco'] = None |
---|
61 | res = context.portal_catalog(container_path=student_path, |
---|
62 | portal_type='StudentClearance') |
---|
63 | if res: |
---|
64 | clear = res[0].getObject() |
---|
65 | info['clear'] = clear |
---|
66 | info['clear_doc'] = clear.getContent() |
---|
67 | info['clear_review_state'] = wf.getInfoFor(clear,'review_state',None) |
---|
68 | else: |
---|
69 | info['clear'] = None |
---|
70 | |
---|
71 | res = context.portal_catalog(container_path=student_path, |
---|
72 | portal_type='StudentPume') |
---|
73 | if res: |
---|
74 | pume = res[0].getObject() |
---|
75 | info['pume'] = clear |
---|
76 | info['pume_doc'] = pume.getContent() |
---|
77 | info['pume_review_state'] = wf.getInfoFor(pume,'review_state',None) |
---|
78 | else: |
---|
79 | info['pume'] = None |
---|
80 | |
---|
81 | items = [] |
---|
82 | s_edit_links = {'StudentApplication': 'application_edit', |
---|
83 | 'StudentAccommodation': '', |
---|
84 | 'StudentClearance': 'clearance_edit', |
---|
85 | 'StudentPersonal': '', |
---|
86 | } |
---|
87 | s_view_links = {'StudentApplication': 'application_view', |
---|
88 | 'StudentAccommodation': 'accommodation_view', |
---|
89 | 'StudentClearance': 'clearance_view', |
---|
90 | 'StudentPersonal': None, |
---|
91 | 'StudentStudyCourse': 'study_course_view', |
---|
92 | 'StudentPume': 'pume_view', |
---|
93 | } |
---|
94 | sos = context.portal_catalog(container_path=student_path) |
---|
95 | for so in sos: |
---|
96 | row = {} |
---|
97 | soo = so.getObject() |
---|
98 | sod = soo.getContent() |
---|
99 | row['id'] = soo.getId() |
---|
100 | row['title'] = sod.Title() |
---|
101 | row['url'] = soo.absolute_url() |
---|
102 | row['type'] = so.portal_type |
---|
103 | row['is_editable'] = mtool.checkPermission('Modify portal content', soo) |
---|
104 | sv_link = s_view_links.get(so.portal_type,None) or "waeup_document_view" |
---|
105 | row['s_view_link'] = "%s/%s" % (soo.absolute_url(),sv_link) |
---|
106 | se_link = s_edit_links.get(so.portal_type,None) |
---|
107 | row['s_edit_link'] = None |
---|
108 | if se_link: |
---|
109 | row['s_edit_link'] = "%s/%s" % (soo.absolute_url(),se_link) |
---|
110 | row['review_state'] = so.review_state |
---|
111 | row['display'] = so.review_state in ('opened','closed','public',) or\ |
---|
112 | so.portal_type in ("StudentAccommodation","StudentStudyCourse") |
---|
113 | items.append(row) |
---|
114 | info['items'] = items |
---|
115 | request.set('student_id',student_id) |
---|
116 | request.set('student_url',info['url']) |
---|
117 | return info |
---|