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, with_items=None |
---|
8 | ##title= |
---|
9 | ## |
---|
10 | # $Id: getStudentInfo.py 1596 2007-03-19 21:45:44Z 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('Skins.getStudentInfo') |
---|
24 | |
---|
25 | |
---|
26 | info = {} |
---|
27 | member_id = str(member) |
---|
28 | #from Products.zdb import set_trace |
---|
29 | #set_trace() |
---|
30 | student_id = None |
---|
31 | if student is None: |
---|
32 | while True: |
---|
33 | if mtool.isAnonymousUser(): |
---|
34 | return None |
---|
35 | try: |
---|
36 | requested_id = path_info[path_info.index('students')+1] |
---|
37 | except (ValueError,IndexError): |
---|
38 | student_id = member_id |
---|
39 | break |
---|
40 | if not context.isStudent() and 'students' in path_info: |
---|
41 | student_id = requested_id |
---|
42 | break |
---|
43 | if member_id != requested_id: |
---|
44 | logger.info('%s tried to access %s' % (member_id,requested_id)) |
---|
45 | student_id = member_id |
---|
46 | mtool.assertViewable(context) |
---|
47 | break |
---|
48 | student_id = member_id |
---|
49 | break |
---|
50 | else: |
---|
51 | student_id = student.getId() |
---|
52 | |
---|
53 | #roles = member.getRoles() |
---|
54 | student_path = "%s/campus/students/%s" % (context.portal_url.getPortalPath(),student_id) |
---|
55 | student = context.restrictedTraverse(student_path,default=None) |
---|
56 | |
---|
57 | if student is None or student.portal_type != "Student": |
---|
58 | return None |
---|
59 | ##res = context.portal_catalog(id = student_id,portal_type='Student') |
---|
60 | ##if not res:# or len(res) > 1: |
---|
61 | ## return None |
---|
62 | ##brain = res[-1] |
---|
63 | ##student = brain.getObject() |
---|
64 | |
---|
65 | info['review_state'] = wf.getInfoFor(student,'review_state',None) |
---|
66 | info['student'] = student |
---|
67 | info['id'] = student.getId() |
---|
68 | info['url'] = student.absolute_url() |
---|
69 | info['student_doc'] = student.getContent() |
---|
70 | info['app'] = student.application |
---|
71 | info['app_doc'] = student.application.getContent() |
---|
72 | #info['per'] = getattr(student,'personal',None) |
---|
73 | #info['sex'] = 'male' |
---|
74 | #if info['per'] is not None: |
---|
75 | # info['per_doc'] = student.personal.getContent() |
---|
76 | # if info['per_doc'].sex: |
---|
77 | # info['sex'] = 'female' |
---|
78 | #else: |
---|
79 | # if info['app_doc'].jamb_sex == "F": |
---|
80 | # info['sex'] = 'female' |
---|
81 | course = getattr(student,'study_course',None) |
---|
82 | if course: |
---|
83 | cert_id = course.getContent().study_course |
---|
84 | res = context.portal_catalog(portal_type = "Certificate", id = cert_id) |
---|
85 | ci = {} |
---|
86 | if len(res) > 0: |
---|
87 | info['course'] = course |
---|
88 | brain = res[0] |
---|
89 | ci['study_course'] = brain.getId |
---|
90 | ci['title'] = brain.Title |
---|
91 | pl = brain.getPath().split('/') |
---|
92 | ci['faculty'] = pl[-4] |
---|
93 | ci['department'] = pl[-3] |
---|
94 | info['course_doc'] = ci |
---|
95 | else: |
---|
96 | info['course'] = None |
---|
97 | # |
---|
98 | acco = getattr(student,'accommodation_2006',None) |
---|
99 | info['acco'] = acco |
---|
100 | if acco is not None: |
---|
101 | info['acco_doc'] = acco.getContent() |
---|
102 | info['acco_review_state'] = wf.getInfoFor(acco,'review_state',None) |
---|
103 | # |
---|
104 | clear = getattr(student,'clearance',None) |
---|
105 | info['clear'] = clear |
---|
106 | if clear is not None: |
---|
107 | info['clear_doc'] = clear.getContent() |
---|
108 | info['clear_review_state'] = wf.getInfoFor(clear,'review_state',None) |
---|
109 | # |
---|
110 | pume = getattr(student,'pume',None) |
---|
111 | info['pume'] = pume |
---|
112 | if pume is not None: |
---|
113 | info['pume_doc'] = pume.getContent() |
---|
114 | info['pume_review_state'] = wf.getInfoFor(pume,'review_state',None) |
---|
115 | else: |
---|
116 | info['pume'] = None |
---|
117 | |
---|
118 | if not with_items: |
---|
119 | return info |
---|
120 | |
---|
121 | items = [] |
---|
122 | s_edit_links = {'StudentApplication': 'application_edit_form', |
---|
123 | 'StudentAccommodation': 'reserve_accommodation', |
---|
124 | 'StudentClearance': 'clearance_edit_form', |
---|
125 | 'StudentPersonal': 'personal_edit_form', |
---|
126 | } |
---|
127 | s_view_links = {'StudentApplication': 'application_view', |
---|
128 | 'StudentAccommodation': 'accommodation_view', |
---|
129 | 'StudentClearance': 'clearance_view', |
---|
130 | 'StudentPersonal': 'personal_view', |
---|
131 | 'StudentStudyCourse': 'study_course_view', |
---|
132 | 'StudentPume': 'pume_view', |
---|
133 | } |
---|
134 | sos = context.portal_catalog(container_path=student_path) |
---|
135 | for so in sos: |
---|
136 | row = {} |
---|
137 | soo = so.getObject() |
---|
138 | sod = soo.getContent() |
---|
139 | row['id'] = soo.getId() |
---|
140 | row['title'] = sod.Title() |
---|
141 | row['url'] = soo.absolute_url() |
---|
142 | row['type'] = so.portal_type |
---|
143 | row['is_editable'] = mtool.checkPermission('Modify portal content', soo) |
---|
144 | sv_link = s_view_links.get(so.portal_type,None) or "waeup_document_view" |
---|
145 | row['s_view_link'] = "%s/%s" % (soo.absolute_url(),sv_link) |
---|
146 | se_link = s_edit_links.get(so.portal_type,None) |
---|
147 | row['s_edit_link'] = None |
---|
148 | if se_link: |
---|
149 | row['s_edit_link'] = "%s/%s" % (soo.absolute_url(),se_link) |
---|
150 | row['review_state'] = so.review_state |
---|
151 | if info['review_state'] in ('returning', |
---|
152 | 'school_fee_paid', |
---|
153 | 'courses_registered', |
---|
154 | 'courses_validated',): |
---|
155 | row['display'] = so.review_state in ('opened', |
---|
156 | 'bed_reserved', |
---|
157 | 'maintenance_fee_paid',) or so.portal_type == 'StudentStudyCourse' |
---|
158 | else: |
---|
159 | row['display'] = so.review_state in ('opened', |
---|
160 | 'closed', |
---|
161 | 'bed_reserved', |
---|
162 | 'maintenance_fee_paid',) and\ |
---|
163 | so.portal_type not in ('StudentPume',) or\ |
---|
164 | so.portal_type == 'StudentStudyCourse' |
---|
165 | |
---|
166 | items.append(row) |
---|
167 | info['items'] = items |
---|
168 | request.set('student_id',student_id) |
---|
169 | request.set('student_url',info['url']) |
---|
170 | return info |
---|