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