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 2745 2007-11-23 13:32:27Z joachim $ |
---|
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 | |
---|
26 | |
---|
27 | info = {} |
---|
28 | member_id = str(member) |
---|
29 | #from Products.zdb import set_trace;set_trace() |
---|
30 | is_student = info['is_student'] = context.isStudent() |
---|
31 | is_staff = info['is_staff'] = context.isStaff() |
---|
32 | is_sectionofficer = info['is_sectionofficer'] = context.isSectionOfficer() |
---|
33 | while True: |
---|
34 | if mtool.isAnonymousUser(): |
---|
35 | return None |
---|
36 | requested_id = context.getStudentId() |
---|
37 | if not is_student and requested_id: |
---|
38 | student_id = requested_id |
---|
39 | break |
---|
40 | if member_id != requested_id: |
---|
41 | logger.info('%s tried to access %s' % (member_id,requested_id)) |
---|
42 | student_id = member_id |
---|
43 | mtool.assertViewable(context) |
---|
44 | break |
---|
45 | student_id = member_id |
---|
46 | break |
---|
47 | student_path_root = "%s/campus/students/%s" % (context.portal_url.getPortalPath(),student_id) |
---|
48 | student_path = "%s/campus/students/%s" % (context.portal_url(),student_id) |
---|
49 | res = context.students_catalog(id = student_id) |
---|
50 | if not res: |
---|
51 | return None |
---|
52 | st_brain = res[0] |
---|
53 | #from Products.zdb import set_trace;set_trace() |
---|
54 | for field in context.students_catalog.schema(): |
---|
55 | info[field] = getattr(st_brain,field) |
---|
56 | |
---|
57 | #res = context.portal_catalog(portal_type='Student',id = student_id) |
---|
58 | #if res: |
---|
59 | # info['review_state'] = res[0].review_state |
---|
60 | |
---|
61 | info['review_state'] = context.getStudentReviewState() |
---|
62 | |
---|
63 | info['session'] = False |
---|
64 | if st_brain.matric_no: |
---|
65 | res = context.results_import(matric_no = st_brain.matric_no) |
---|
66 | if res: |
---|
67 | info['session'] = True |
---|
68 | |
---|
69 | info['base_info'] = context.getFormattedStudentEntry(st_brain) |
---|
70 | |
---|
71 | info['id'] = student_id |
---|
72 | items = [] |
---|
73 | s_edit_links = {'StudentApplication': 'application_edit_form', |
---|
74 | 'StudentAccommodation': 'reserve_accommodation', |
---|
75 | 'StudentClearance': 'clearance_edit_form', |
---|
76 | 'StudentPersonal': 'personal_edit_form', |
---|
77 | } |
---|
78 | s_view_links = {'StudentApplication': 'application_view', |
---|
79 | 'StudentAccommodation': 'accommodation_view', |
---|
80 | 'StudentClearance': 'clearance_view', |
---|
81 | 'StudentPersonal': 'personal_view', |
---|
82 | 'StudentStudyCourse': 'study_course_view', |
---|
83 | 'PaymentsFolder': 'payments_view', |
---|
84 | } |
---|
85 | #logger.info("before search") |
---|
86 | starttime = DateTime.DateTime().timeTime() |
---|
87 | sos = context.portal_catalog(container_path=student_path_root) |
---|
88 | logger.info("searchtime %f" % (DateTime.DateTime().timeTime() - starttime)) |
---|
89 | starttime = DateTime.DateTime().timeTime() |
---|
90 | for so in sos: |
---|
91 | row = {} |
---|
92 | row['id'] = so.getId |
---|
93 | row['title'] = so.Title |
---|
94 | url = row['url'] = "%s/%s" % (student_path,so.getId) |
---|
95 | row['type'] = so.portal_type |
---|
96 | review_state = row['review_state'] = so.review_state |
---|
97 | row['is_editable'] = (is_student and review_state == "opened") or is_sectionofficer |
---|
98 | sv_link = s_view_links.get(so.portal_type,None) or "waeup_document_view" |
---|
99 | row['s_view_link'] = "%s/%s" % (url,sv_link) |
---|
100 | se_link = s_edit_links.get(so.portal_type,None) |
---|
101 | row['s_edit_link'] = None |
---|
102 | if se_link: |
---|
103 | row['s_edit_link'] = "%s/%s" % (url,se_link) |
---|
104 | row['display'] = review_state in ('opened','closed','bed_reserved','maintenance_fee_paid',)\ |
---|
105 | and so.portal_type not in ('StudentPume','StudentAccommodation','PaymentsFolder',) or\ |
---|
106 | so.portal_type == 'StudentStudyCourse' |
---|
107 | items.append(row) |
---|
108 | logger.info("listtime %f" % (DateTime.DateTime().timeTime() - starttime)) |
---|
109 | items.sort(cmp=lambda x,y: cmp( x['title'],y['title'])) |
---|
110 | info['items'] = items |
---|
111 | info['member'] = member |
---|
112 | return info |
---|
113 | |
---|