[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 3479 2008-05-01 05:47:45Z henrik $ |
---|
| 11 | """ |
---|
| 12 | return Info about the current Student |
---|
[2837] | 13 | try: |
---|
| 14 | from Products.zdb import set_trace |
---|
| 15 | except: |
---|
| 16 | def set_trace(): |
---|
| 17 | pass |
---|
[1185] | 18 | """ |
---|
[2745] | 19 | import DateTime |
---|
[1185] | 20 | request = context.REQUEST |
---|
| 21 | form = request.form |
---|
| 22 | fget = form.get |
---|
| 23 | wf = context.portal_workflow |
---|
| 24 | mtool = context.portal_membership |
---|
| 25 | member = mtool.getAuthenticatedMember() |
---|
| 26 | path_info = request.get('PATH_INFO').split('/') |
---|
| 27 | |
---|
| 28 | import logging |
---|
[1571] | 29 | logger = logging.getLogger('Skins.getStudentFolderInfo') |
---|
[2806] | 30 | from Products.AdvancedQuery import Eq, Between, Le,In |
---|
| 31 | try: |
---|
| 32 | aq_portal = context.portal_catalog.evalAdvancedQuery |
---|
| 33 | except: |
---|
| 34 | aq_portal = context.portal_catalog_real.evalAdvancedQuery |
---|
[1185] | 35 | |
---|
| 36 | |
---|
| 37 | member_id = str(member) |
---|
[1243] | 38 | #from Products.zdb import set_trace;set_trace() |
---|
[2975] | 39 | # info = {} |
---|
| 40 | # is_student = info['is_student'] = context.isStudent() |
---|
| 41 | # is_staff = info['is_staff'] = context.isStaff() |
---|
| 42 | # is_sectionofficer = info['is_sectionofficer'] = context.isSectionOfficer() |
---|
| 43 | # while True: |
---|
| 44 | # if mtool.isAnonymousUser(): |
---|
| 45 | # return None |
---|
| 46 | # requested_id = context.getStudentId() |
---|
| 47 | # if not is_student and requested_id: |
---|
| 48 | # student_id = requested_id |
---|
| 49 | # break |
---|
| 50 | # if member_id != requested_id: |
---|
| 51 | # logger.info('%s tried to access %s' % (member_id,requested_id)) |
---|
| 52 | # student_id = member_id |
---|
| 53 | # mtool.assertViewable(context) |
---|
| 54 | # break |
---|
| 55 | # student_id = member_id |
---|
| 56 | # break |
---|
| 57 | info = context.waeup_tool.getAccessInfo(context) |
---|
| 58 | student_id = info['student_id'] |
---|
| 59 | if student_id is None: |
---|
| 60 | return None |
---|
| 61 | |
---|
[1431] | 62 | student_path_root = "%s/campus/students/%s" % (context.portal_url.getPortalPath(),student_id) |
---|
| 63 | student_path = "%s/campus/students/%s" % (context.portal_url(),student_id) |
---|
[2806] | 64 | students_folder = context.portal_url.getPortalObject().campus.students |
---|
[2961] | 65 | |
---|
[2806] | 66 | student_record = context.students_catalog.getRecordByKey(student_id) |
---|
| 67 | if student_record is None: |
---|
[1185] | 68 | return None |
---|
[2831] | 69 | |
---|
[1185] | 70 | #from Products.zdb import set_trace;set_trace() |
---|
| 71 | for field in context.students_catalog.schema(): |
---|
[2806] | 72 | info[field] = getattr(student_record,field) |
---|
[1359] | 73 | |
---|
[2806] | 74 | #info['review_state'] = context.getStudentReviewState() |
---|
[1871] | 75 | |
---|
[1422] | 76 | info['session'] = False |
---|
[2806] | 77 | if student_record.matric_no: |
---|
| 78 | res = context.results_import(matric_no = student_record.matric_no) |
---|
[1422] | 79 | if res: |
---|
| 80 | info['session'] = True |
---|
| 81 | |
---|
[2831] | 82 | info['base_info'] = context.getFormattedStudentEntry(student_record) |
---|
[1472] | 83 | |
---|
[1185] | 84 | info['id'] = student_id |
---|
| 85 | items = [] |
---|
| 86 | s_edit_links = {'StudentApplication': 'application_edit_form', |
---|
| 87 | 'StudentAccommodation': 'reserve_accommodation', |
---|
| 88 | 'StudentClearance': 'clearance_edit_form', |
---|
| 89 | 'StudentPersonal': 'personal_edit_form', |
---|
| 90 | } |
---|
| 91 | s_view_links = {'StudentApplication': 'application_view', |
---|
| 92 | 'StudentAccommodation': 'accommodation_view', |
---|
| 93 | 'StudentClearance': 'clearance_view', |
---|
| 94 | 'StudentPersonal': 'personal_view', |
---|
| 95 | 'StudentStudyCourse': 'study_course_view', |
---|
[1243] | 96 | 'PaymentsFolder': 'payments_view', |
---|
[1185] | 97 | } |
---|
[3473] | 98 | s_view_titles = context.getStudentObjectTitles() |
---|
[2961] | 99 | |
---|
[2806] | 100 | student_obj = getattr(students_folder,student_id) |
---|
| 101 | subobjects = student_obj.objectValues() |
---|
[2961] | 102 | |
---|
[2806] | 103 | for subobject in subobjects: |
---|
[1185] | 104 | row = {} |
---|
[2806] | 105 | row['id'] = subobject.getId() |
---|
[3473] | 106 | if subobject.portal_type == 'StudentAccommodation': |
---|
[3479] | 107 | row['title'] = s_view_titles.get(subobject.portal_type,'') +' for Session %s' %\ |
---|
[3473] | 108 | context.portal_vocabularies.sessions.get(subobject.getContent().session) |
---|
[3479] | 109 | #row['title'] = s_view_titles.get(subobject.portal_type,'') +' %s' %subobject.getContent().session |
---|
[3473] | 110 | else: |
---|
| 111 | row['title'] = s_view_titles.get(subobject.portal_type,'') |
---|
[2806] | 112 | url = row['url'] = subobject.absolute_url() |
---|
| 113 | row['type'] = subobject.portal_type |
---|
| 114 | review_state = row['review_state'] = wf.getInfoFor(subobject,'review_state',None) |
---|
[2975] | 115 | row['is_editable'] = (info['is_student'] and review_state == "opened") or info['is_sectionofficer'] |
---|
[2806] | 116 | sv_link = s_view_links.get(subobject.portal_type,None) or "waeup_document_view" |
---|
[1185] | 117 | row['s_view_link'] = "%s/%s" % (url,sv_link) |
---|
[2806] | 118 | se_link = s_edit_links.get(subobject.portal_type,None) |
---|
[1185] | 119 | row['s_edit_link'] = None |
---|
| 120 | if se_link: |
---|
| 121 | row['s_edit_link'] = "%s/%s" % (url,se_link) |
---|
| 122 | row['display'] = review_state in ('opened','closed','bed_reserved','maintenance_fee_paid',)\ |
---|
[2806] | 123 | and subobject.portal_type not in ('StudentPume','StudentAccommodation','PaymentsFolder',) or\ |
---|
| 124 | subobject.portal_type == 'StudentStudyCourse' |
---|
[1185] | 125 | items.append(row) |
---|
[2961] | 126 | |
---|
[2477] | 127 | items.sort(cmp=lambda x,y: cmp( x['title'],y['title'])) |
---|
[1185] | 128 | info['items'] = items |
---|
[1214] | 129 | info['member'] = member |
---|
[2961] | 130 | |
---|
| 131 | try: |
---|
| 132 | current_level = int(info['level']) |
---|
| 133 | except: |
---|
| 134 | current_level = 0 |
---|
[3479] | 135 | info['transition_return_allowed'] = info['review_state'] == 'school_fee_paid' and info['is_sectionofficer'] # and current_level > 100 |
---|
[2983] | 136 | info['transition_pay_school_fee_allowed'] = info['review_state'] == 'returning' and info['is_sectionofficer'] |
---|
[2961] | 137 | |
---|
[1185] | 138 | return info |
---|
[1258] | 139 | |
---|