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 1006 2006-12-07 18:18:28Z 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 | |
---|
22 | import logging |
---|
23 | logger = logging.getLogger('getStudentInfo') |
---|
24 | |
---|
25 | info = {} |
---|
26 | member_id = str(member) |
---|
27 | #from Products.zdb import set_trace |
---|
28 | #set_trace() |
---|
29 | student_id = None |
---|
30 | if student is None: |
---|
31 | while True: |
---|
32 | if mtool.isAnonymousUser(): |
---|
33 | return None |
---|
34 | try: |
---|
35 | requested_id = path_info[path_info.index('students')+1] |
---|
36 | except ValueError: |
---|
37 | student_id = member_id |
---|
38 | break |
---|
39 | if not context.isStudent() and 'students' in path_info: |
---|
40 | student_id = requested_id |
---|
41 | break |
---|
42 | if member_id != requested_id: |
---|
43 | logger.info("Student %s tried to access %s" % (member_id,requested_id)) |
---|
44 | student_id = member_id |
---|
45 | #mtool.assertViewable(context) |
---|
46 | break |
---|
47 | student_id = member_id |
---|
48 | break |
---|
49 | else: |
---|
50 | student_id = student.getId() |
---|
51 | |
---|
52 | roles = member.getRoles() |
---|
53 | student_path = "%s/campus/students/%s" % (context.portal_url.getPortalPath(),student_id) |
---|
54 | student = context.restrictedTraverse(student_path,default=None) |
---|
55 | |
---|
56 | if student is None or student.portal_type != "Student": |
---|
57 | return None |
---|
58 | ##res = context.portal_catalog(id = student_id,portal_type='Student') |
---|
59 | ##if not res:# or len(res) > 1: |
---|
60 | ## return None |
---|
61 | ##brain = res[-1] |
---|
62 | ##student = brain.getObject() |
---|
63 | info['review_state'] = wf.getInfoFor(student,'review_state',None) |
---|
64 | info['student'] = student |
---|
65 | info['id'] = student.getId() |
---|
66 | info['url'] = student.absolute_url() |
---|
67 | info['student_doc'] = student.getContent() |
---|
68 | info['app'] = student.application |
---|
69 | info['app_doc'] = student.application.getContent() |
---|
70 | info['per'] = getattr(student,'personal',None) |
---|
71 | info['sex'] = 'male' |
---|
72 | if info['per'] is not None: |
---|
73 | info['per_doc'] = student.personal.getContent() |
---|
74 | if info['per_doc'].sex: |
---|
75 | info['sex'] = 'female' |
---|
76 | else: |
---|
77 | if info['app_doc'].jamb_sex == "F": |
---|
78 | info['sex'] = 'female' |
---|
79 | course = getattr(student,'study_course',None) |
---|
80 | info['course'] = course |
---|
81 | if course: |
---|
82 | info['course_doc'] = student.study_course.getContent() |
---|
83 | # |
---|
84 | acco = getattr(student,'accommodation_2006',None) |
---|
85 | info['acco'] = acco |
---|
86 | if acco is not None: |
---|
87 | info['acco_doc'] = acco.getContent() |
---|
88 | info['acco_review_state'] = wf.getInfoFor(acco,'review_state',None) |
---|
89 | # |
---|
90 | clear = getattr(student,'clearance',None) |
---|
91 | info['clear'] = clear |
---|
92 | if clear is not None: |
---|
93 | info['clear_doc'] = clear.getContent() |
---|
94 | info['clear_review_state'] = wf.getInfoFor(clear,'review_state',None) |
---|
95 | # |
---|
96 | pume = getattr(student,'pume',None) |
---|
97 | info['pume'] = pume |
---|
98 | if pume is not None: |
---|
99 | info['pume_doc'] = pume.getContent() |
---|
100 | info['pume_review_state'] = wf.getInfoFor(pume,'review_state',None) |
---|
101 | else: |
---|
102 | info['pume'] = None |
---|
103 | |
---|
104 | items = [] |
---|
105 | s_edit_links = {'StudentApplication': 'application_edit_form', |
---|
106 | 'StudentAccommodation': 'reserve_accommodation', |
---|
107 | 'StudentClearance': 'clearance_edit_form', |
---|
108 | 'StudentPersonal': '', |
---|
109 | } |
---|
110 | s_view_links = {'StudentApplication': 'application_view', |
---|
111 | 'StudentAccommodation': 'accommodation_view', |
---|
112 | 'StudentClearance': 'clearance_view', |
---|
113 | 'StudentPersonal': None, |
---|
114 | 'StudentStudyCourse': 'study_course_view', |
---|
115 | 'StudentPume': 'pume_view', |
---|
116 | } |
---|
117 | sos = context.portal_catalog(container_path=student_path) |
---|
118 | for so in sos: |
---|
119 | row = {} |
---|
120 | soo = so.getObject() |
---|
121 | sod = soo.getContent() |
---|
122 | row['id'] = soo.getId() |
---|
123 | row['title'] = sod.Title() |
---|
124 | row['url'] = soo.absolute_url() |
---|
125 | row['type'] = so.portal_type |
---|
126 | row['is_editable'] = mtool.checkPermission('Modify portal content', soo) |
---|
127 | sv_link = s_view_links.get(so.portal_type,None) or "waeup_document_view" |
---|
128 | row['s_view_link'] = "%s/%s" % (soo.absolute_url(),sv_link) |
---|
129 | se_link = s_edit_links.get(so.portal_type,None) |
---|
130 | row['s_edit_link'] = None |
---|
131 | if se_link: |
---|
132 | row['s_edit_link'] = "%s/%s" % (soo.absolute_url(),se_link) |
---|
133 | row['review_state'] = so.review_state |
---|
134 | row['display'] = so.review_state in ('opened','closed',) |
---|
135 | items.append(row) |
---|
136 | info['items'] = items |
---|
137 | request.set('student_id',student_id) |
---|
138 | request.set('student_url',info['url']) |
---|
139 | return info |
---|