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 | info = {} |
---|
23 | info['is_manager'] = context.isManager |
---|
24 | info['is_student'] = context.isStudent() |
---|
25 | member_id = str(member) |
---|
26 | if student is None: |
---|
27 | if context.isManager(): |
---|
28 | if context.portal_type == 'Student': |
---|
29 | student_id = context.getId() |
---|
30 | else: |
---|
31 | student_id = context.aq_parent.getId() |
---|
32 | else: |
---|
33 | student_id = member_id |
---|
34 | else: |
---|
35 | student_id = student.getId() |
---|
36 | res = context.portal_catalog(id = student_id,portal_type='Student') |
---|
37 | if not res or len(res) > 1: |
---|
38 | return None |
---|
39 | brain = res[-1] |
---|
40 | student = brain.getObject() |
---|
41 | student_path = brain.getPath() |
---|
42 | info['review_state'] = wf.getInfoFor(student,'review_state','keiner') |
---|
43 | info['student'] = student |
---|
44 | info['id'] = student.getId() |
---|
45 | info['url'] = student.absolute_url() |
---|
46 | info['student_doc'] = student.getContent() |
---|
47 | info['app'] = student.application |
---|
48 | info['app_doc'] = student.application.getContent() |
---|
49 | info['per'] = student.personal |
---|
50 | info['per_doc'] = student.personal.getContent() |
---|
51 | info['sex'] = 'male' |
---|
52 | if info['per_doc'].sex: |
---|
53 | info['sex'] = 'female' |
---|
54 | res = context.portal_catalog(container_path=student_path, |
---|
55 | portal_type='StudentAccommodation') |
---|
56 | if res: |
---|
57 | acco = res[0].getObject() |
---|
58 | info['acco'] = acco |
---|
59 | info['acco_doc'] = acco.getContent() |
---|
60 | else: |
---|
61 | info['acco'] = None |
---|
62 | |
---|
63 | items = [] |
---|
64 | s_edit_links = {'StudentApplication': 'student_edit', |
---|
65 | 'StudentAccommodation': '', |
---|
66 | 'StudentPersonal': '', |
---|
67 | } |
---|
68 | s_view_links = {'StudentApplication': 'application_view', |
---|
69 | 'StudentAccommodation': 'accommodation_view', |
---|
70 | 'StudentPersonal': 'personal_view', |
---|
71 | } |
---|
72 | sos = context.portal_catalog(container_path=student_path) |
---|
73 | for so in sos: |
---|
74 | row = {} |
---|
75 | soo = so.getObject() |
---|
76 | sod = soo.getContent() |
---|
77 | row['id'] = soo.getId() |
---|
78 | row['title'] = sod.Title() |
---|
79 | row['url'] = soo.absolute_url() |
---|
80 | row['type'] = so.portal_type |
---|
81 | row['is_editable'] = mtool.checkPermission('Modify portal content', soo) |
---|
82 | sv_link = s_view_links.get(so.portal_type,None) |
---|
83 | row['s_view_link'] = None |
---|
84 | if sv_link: |
---|
85 | row['s_view_link'] = "%s/%s" % (student.absolute_url(),sv_link) |
---|
86 | se_link = s_edit_links.get(so.portal_type,None) |
---|
87 | row['s_edit_link'] = None |
---|
88 | if se_link: |
---|
89 | row['s_edit_link'] = "%s/%s" % (student.absolute_url(),se_link) |
---|
90 | row['review_state'] = so.review_state |
---|
91 | row['display'] = so.review_state in ('opened','closed') |
---|
92 | items.append(row) |
---|
93 | info['items'] = items |
---|
94 | return info |
---|