1 | ## Script (Python) "getStudentInfo" |
---|
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: getStudentInfo.py 913 2006-11-21 10:49:45Z henrik $ |
---|
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 | |
---|
22 | info = {} |
---|
23 | member_id = str(member) |
---|
24 | if student is None: |
---|
25 | if mtool.isAnonymousUser(): |
---|
26 | return None |
---|
27 | elif not context.isStudent() and 'students' in path_info: |
---|
28 | student_id = path_info[path_info.index('students')+1] |
---|
29 | else: |
---|
30 | student_id = member_id |
---|
31 | else: |
---|
32 | student_id = student.getId() |
---|
33 | roles = member.getRoles() |
---|
34 | student_path = "%s/campus/students/%s" % (context.portal_url.getPortalPath(),student_id) |
---|
35 | student = context.restrictedTraverse(student_path,default=None) |
---|
36 | if student is None or student.portal_type != 'Student': |
---|
37 | return None |
---|
38 | ##res = context.portal_catalog(id = student_id,portal_type='Student') |
---|
39 | ##if not res:# or len(res) > 1: |
---|
40 | ## return None |
---|
41 | ##brain = res[-1] |
---|
42 | ##student = brain.getObject() |
---|
43 | info['review_state'] = wf.getInfoFor(student,'review_state',None) |
---|
44 | info['student'] = student |
---|
45 | info['id'] = student.getId() |
---|
46 | info['url'] = student.absolute_url() |
---|
47 | info['student_doc'] = student.getContent() |
---|
48 | info['app'] = student.application |
---|
49 | info['app_doc'] = student.application.getContent() |
---|
50 | info['per'] = student.personal |
---|
51 | info['per_doc'] = student.personal.getContent() |
---|
52 | course = getattr(student,'study_course',None) |
---|
53 | # |
---|
54 | info['course'] = course |
---|
55 | if course: |
---|
56 | info['course_doc'] = student.study_course.getContent() |
---|
57 | info['sex'] = 'male' |
---|
58 | if info['per_doc'].sex: |
---|
59 | info['sex'] = 'female' |
---|
60 | # |
---|
61 | acco = getattr(student,'accommodation_2006',None) |
---|
62 | info['acco'] = acco |
---|
63 | if acco is not None: |
---|
64 | info['acco_doc'] = acco.getContent() |
---|
65 | info['acco_review_state'] = wf.getInfoFor(acco,'review_state',None) |
---|
66 | # |
---|
67 | clear = getattr(student,'clearance',None) |
---|
68 | info['clear'] = clear |
---|
69 | if clear is not None: |
---|
70 | info['clear_doc'] = clear.getContent() |
---|
71 | info['clear_review_state'] = wf.getInfoFor(clear,'review_state',None) |
---|
72 | # |
---|
73 | pume = getattr(student,'pume',None) |
---|
74 | info['pume'] = pume |
---|
75 | if pume is not None: |
---|
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_form', |
---|
83 | 'StudentAccommodation': 'reserve_accommodation', |
---|
84 | 'StudentClearance': 'clearance_edit_form', |
---|
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',) |
---|
112 | items.append(row) |
---|
113 | info['items'] = items |
---|
114 | request.set('student_id',student_id) |
---|
115 | request.set('student_url',info['url']) |
---|
116 | return info |
---|