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