1 | ## Script (Python) "getStudentFolderInfo" |
---|
2 | ##bind container=container |
---|
3 | ##bind context=context |
---|
4 | ##bind namespace= |
---|
5 | ##bind script=script |
---|
6 | ##bind subpath=traverse_subpath |
---|
7 | ##parameters=with_items=None |
---|
8 | ##title= |
---|
9 | ## |
---|
10 | # $Id: getStudentFolderInfo.py 2831 2007-11-30 11:46:03Z henrik $ |
---|
11 | """ |
---|
12 | return Info about the current Student |
---|
13 | """ |
---|
14 | import DateTime |
---|
15 | request = context.REQUEST |
---|
16 | form = request.form |
---|
17 | fget = form.get |
---|
18 | wf = context.portal_workflow |
---|
19 | mtool = context.portal_membership |
---|
20 | member = mtool.getAuthenticatedMember() |
---|
21 | path_info = request.get('PATH_INFO').split('/') |
---|
22 | |
---|
23 | import logging |
---|
24 | logger = logging.getLogger('Skins.getStudentFolderInfo') |
---|
25 | from Products.AdvancedQuery import Eq, Between, Le,In |
---|
26 | try: |
---|
27 | aq_portal = context.portal_catalog.evalAdvancedQuery |
---|
28 | except: |
---|
29 | aq_portal = context.portal_catalog_real.evalAdvancedQuery |
---|
30 | |
---|
31 | |
---|
32 | info = {} |
---|
33 | member_id = str(member) |
---|
34 | #from Products.zdb import set_trace;set_trace() |
---|
35 | is_student = info['is_student'] = context.isStudent() |
---|
36 | is_staff = info['is_staff'] = context.isStaff() |
---|
37 | is_sectionofficer = info['is_sectionofficer'] = context.isSectionOfficer() |
---|
38 | while True: |
---|
39 | if mtool.isAnonymousUser(): |
---|
40 | return None |
---|
41 | requested_id = context.getStudentId() |
---|
42 | if not is_student and requested_id: |
---|
43 | student_id = requested_id |
---|
44 | break |
---|
45 | if member_id != requested_id: |
---|
46 | logger.info('%s tried to access %s' % (member_id,requested_id)) |
---|
47 | student_id = member_id |
---|
48 | mtool.assertViewable(context) |
---|
49 | break |
---|
50 | student_id = member_id |
---|
51 | break |
---|
52 | student_path_root = "%s/campus/students/%s" % (context.portal_url.getPortalPath(),student_id) |
---|
53 | student_path = "%s/campus/students/%s" % (context.portal_url(),student_id) |
---|
54 | students_folder = context.portal_url.getPortalObject().campus.students |
---|
55 | # res = context.students_catalog(id = student_id) |
---|
56 | # if not res: |
---|
57 | # return None |
---|
58 | # student_record = res[0] |
---|
59 | student_record = context.students_catalog.getRecordByKey(student_id) |
---|
60 | if student_record is None: |
---|
61 | return None |
---|
62 | |
---|
63 | #from Products.zdb import set_trace;set_trace() |
---|
64 | for field in context.students_catalog.schema(): |
---|
65 | info[field] = getattr(student_record,field) |
---|
66 | |
---|
67 | #res = context.portal_catalog(portal_type='Student',id = student_id) |
---|
68 | #if res: |
---|
69 | # info['review_state'] = res[0].review_state |
---|
70 | |
---|
71 | #info['review_state'] = context.getStudentReviewState() |
---|
72 | |
---|
73 | info['session'] = False |
---|
74 | if student_record.matric_no: |
---|
75 | res = context.results_import(matric_no = student_record.matric_no) |
---|
76 | if res: |
---|
77 | info['session'] = True |
---|
78 | |
---|
79 | info['base_info'] = context.getFormattedStudentEntry(student_record) |
---|
80 | |
---|
81 | info['id'] = student_id |
---|
82 | items = [] |
---|
83 | s_edit_links = {'StudentApplication': 'application_edit_form', |
---|
84 | 'StudentAccommodation': 'reserve_accommodation', |
---|
85 | 'StudentClearance': 'clearance_edit_form', |
---|
86 | 'StudentPersonal': 'personal_edit_form', |
---|
87 | } |
---|
88 | s_view_links = {'StudentApplication': 'application_view', |
---|
89 | 'StudentAccommodation': 'accommodation_view', |
---|
90 | 'StudentClearance': 'clearance_view', |
---|
91 | 'StudentPersonal': 'personal_view', |
---|
92 | 'StudentStudyCourse': 'study_course_view', |
---|
93 | 'PaymentsFolder': 'payments_view', |
---|
94 | } |
---|
95 | #logger.info("before search") |
---|
96 | #starttime = DateTime.DateTime().timeTime() |
---|
97 | #sos = context.portal_catalog(container_path=student_path_root) |
---|
98 | # query = Eq('container_path',student_path_root) |
---|
99 | # sos = aq_portal(query) |
---|
100 | # logger.info("searchtime %f" % (DateTime.DateTime().timeTime() - starttime)) |
---|
101 | # starttime = DateTime.DateTime().timeTime() |
---|
102 | # for so in sos: |
---|
103 | # row = {} |
---|
104 | # row['id'] = so.getId |
---|
105 | # row['title'] = so.Title |
---|
106 | # url = row['url'] = "%s/%s" % (student_path,so.getId) |
---|
107 | # row['type'] = so.portal_type |
---|
108 | # review_state = row['review_state'] = so.review_state |
---|
109 | # row['is_editable'] = (is_student and review_state == "opened") or is_sectionofficer |
---|
110 | # sv_link = s_view_links.get(so.portal_type,None) or "waeup_document_view" |
---|
111 | # row['s_view_link'] = "%s/%s" % (url,sv_link) |
---|
112 | # se_link = s_edit_links.get(so.portal_type,None) |
---|
113 | # row['s_edit_link'] = None |
---|
114 | # if se_link: |
---|
115 | # row['s_edit_link'] = "%s/%s" % (url,se_link) |
---|
116 | # row['display'] = review_state in ('opened','closed','bed_reserved','maintenance_fee_paid',)\ |
---|
117 | # and so.portal_type not in ('StudentPume','StudentAccommodation','PaymentsFolder',) or\ |
---|
118 | # so.portal_type == 'StudentStudyCourse' |
---|
119 | # items.append(row) |
---|
120 | #sos = context.portal_catalog(container_path=student_path_root) |
---|
121 | student_obj = getattr(students_folder,student_id) |
---|
122 | subobjects = student_obj.objectValues() |
---|
123 | #logger.info("searchtime %f" % (DateTime.DateTime().timeTime() - starttime)) |
---|
124 | #starttime = DateTime.DateTime().timeTime() |
---|
125 | for subobject in subobjects: |
---|
126 | row = {} |
---|
127 | row['id'] = subobject.getId() |
---|
128 | row['title'] = subobject.Title |
---|
129 | url = row['url'] = subobject.absolute_url() |
---|
130 | row['type'] = subobject.portal_type |
---|
131 | review_state = row['review_state'] = wf.getInfoFor(subobject,'review_state',None) |
---|
132 | row['is_editable'] = (is_student and review_state == "opened") or is_sectionofficer |
---|
133 | sv_link = s_view_links.get(subobject.portal_type,None) or "waeup_document_view" |
---|
134 | row['s_view_link'] = "%s/%s" % (url,sv_link) |
---|
135 | se_link = s_edit_links.get(subobject.portal_type,None) |
---|
136 | row['s_edit_link'] = None |
---|
137 | if se_link: |
---|
138 | row['s_edit_link'] = "%s/%s" % (url,se_link) |
---|
139 | row['display'] = review_state in ('opened','closed','bed_reserved','maintenance_fee_paid',)\ |
---|
140 | and subobject.portal_type not in ('StudentPume','StudentAccommodation','PaymentsFolder',) or\ |
---|
141 | subobject.portal_type == 'StudentStudyCourse' |
---|
142 | items.append(row) |
---|
143 | #logger.info("listtime %f" % (DateTime.DateTime().timeTime() - starttime)) |
---|
144 | items.sort(cmp=lambda x,y: cmp( x['title'],y['title'])) |
---|
145 | info['items'] = items |
---|
146 | info['member'] = member |
---|
147 | return info |
---|
148 | |
---|