| 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 5620 2010-12-27 17:26:24Z henrik $ |
|---|
| 11 | """ |
|---|
| 12 | return Info about the current Student |
|---|
| 13 | try: |
|---|
| 14 | from Products.zdb import set_trace |
|---|
| 15 | except: |
|---|
| 16 | def set_trace(): |
|---|
| 17 | pass |
|---|
| 18 | """ |
|---|
| 19 | import DateTime |
|---|
| 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 |
|---|
| 29 | logger = logging.getLogger('Skins.getStudentFolderInfo') |
|---|
| 30 | from Products.AdvancedQuery import Eq, Between, Le,In |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | member_id = str(member) |
|---|
| 34 | |
|---|
| 35 | info = context.waeup_tool.getAccessInfo(context) |
|---|
| 36 | student_id = info['student_id'] |
|---|
| 37 | if student_id is None: |
|---|
| 38 | return None |
|---|
| 39 | |
|---|
| 40 | student_path_root = "%s/campus/students/%s" % (context.portal_url.getPortalPath(),student_id) |
|---|
| 41 | student_path = "%s/campus/students/%s" % (context.portal_url(),student_id) |
|---|
| 42 | students_folder = context.portal_url.getPortalObject().campus.students |
|---|
| 43 | |
|---|
| 44 | student_record = context.students_catalog.getRecordByKey(student_id) |
|---|
| 45 | if student_record is None: |
|---|
| 46 | return None |
|---|
| 47 | |
|---|
| 48 | #from Products.zdb import set_trace;set_trace() |
|---|
| 49 | for field in context.students_catalog.schema(): |
|---|
| 50 | info[field] = getattr(student_record,field) |
|---|
| 51 | |
|---|
| 52 | #info['review_state'] = context.getStudentReviewState() |
|---|
| 53 | |
|---|
| 54 | info['session'] = False |
|---|
| 55 | if student_record.matric_no and 'uniben' in context.portal_url.getPortalPath(): |
|---|
| 56 | res = context.results_import(matric_no = student_record.matric_no) |
|---|
| 57 | if res: |
|---|
| 58 | info['session'] = True |
|---|
| 59 | |
|---|
| 60 | info['base_info'] = context.getFormattedStudentEntry(student_record) |
|---|
| 61 | |
|---|
| 62 | info['id'] = student_id |
|---|
| 63 | items = [] |
|---|
| 64 | s_edit_links = {'StudentApplication': 'application_edit_form', |
|---|
| 65 | 'StudentAccommodation': 'reserve_accommodation', |
|---|
| 66 | 'StudentClearance': 'clearance_edit_form', |
|---|
| 67 | 'StudentPersonal': 'personal_edit_form', |
|---|
| 68 | } |
|---|
| 69 | s_view_links = {'StudentApplication': 'application_view', |
|---|
| 70 | 'StudentAccommodation': 'accommodation_view', |
|---|
| 71 | 'StudentClearance': 'clearance_view', |
|---|
| 72 | 'StudentPersonal': 'personal_view', |
|---|
| 73 | 'StudentStudyCourse': 'study_course_view', |
|---|
| 74 | 'PaymentsFolder': 'payments_view', |
|---|
| 75 | } |
|---|
| 76 | s_view_titles = context.getStudentObjectTitles() |
|---|
| 77 | |
|---|
| 78 | student_obj = getattr(students_folder,student_id) |
|---|
| 79 | subobjects = student_obj.objectValues() |
|---|
| 80 | |
|---|
| 81 | for subobject in subobjects: |
|---|
| 82 | row = {} |
|---|
| 83 | row['id'] = subobject.getId() |
|---|
| 84 | if subobject.portal_type == 'StudentAccommodation' and member_id != 'admin': |
|---|
| 85 | continue |
|---|
| 86 | if subobject.portal_type == 'StudentAccommodation': |
|---|
| 87 | row['title'] = s_view_titles.get(subobject.portal_type,'') +' for Session %s' %\ |
|---|
| 88 | context.portal_vocabularies.sessions.get(subobject.getContent().session) |
|---|
| 89 | #row['title'] = s_view_titles.get(subobject.portal_type,'') +' %s' %subobject.getContent().session |
|---|
| 90 | else: |
|---|
| 91 | row['title'] = s_view_titles.get(subobject.portal_type,'') |
|---|
| 92 | url = row['url'] = subobject.absolute_url() |
|---|
| 93 | row['type'] = subobject.portal_type |
|---|
| 94 | review_state = row['review_state'] = wf.getInfoFor(subobject,'review_state',None) |
|---|
| 95 | row['is_editable'] = (info['is_student'] and review_state == "opened") or info['is_sectionofficer'] |
|---|
| 96 | sv_link = s_view_links.get(subobject.portal_type,None) or "waeup_document_view" |
|---|
| 97 | row['s_view_link'] = "%s/%s" % (url,sv_link) |
|---|
| 98 | se_link = s_edit_links.get(subobject.portal_type,None) |
|---|
| 99 | row['s_edit_link'] = None |
|---|
| 100 | if se_link: |
|---|
| 101 | row['s_edit_link'] = "%s/%s" % (url,se_link) |
|---|
| 102 | row['display'] = review_state in ('opened','closed','bed_reserved','maintenance_fee_paid',)\ |
|---|
| 103 | and subobject.portal_type not in ('StudentPume','StudentAccommodation','PaymentsFolder',) or\ |
|---|
| 104 | subobject.portal_type == 'StudentStudyCourse' |
|---|
| 105 | items.append(row) |
|---|
| 106 | |
|---|
| 107 | items.sort(cmp=lambda x,y: cmp( x['title'],y['title'])) |
|---|
| 108 | info['items'] = items |
|---|
| 109 | info['member'] = member |
|---|
| 110 | |
|---|
| 111 | try: |
|---|
| 112 | current_level = int(info['level']) |
|---|
| 113 | except: |
|---|
| 114 | current_level = 0 |
|---|
| 115 | info['transition_return_allowed'] = info['review_state'] in ('school_fee_paid','courses_validated','graduated') and info['is_sectionofficer'] # and current_level > 100 |
|---|
| 116 | info['transition_pay_school_fee_allowed'] = info['review_state'] == 'returning' and info['is_sectionofficer'] |
|---|
| 117 | info['transition_admit_allowed'] = info['review_state'] == 'returning' and info['is_sectionofficer'] |
|---|
| 118 | |
|---|
| 119 | return info |
|---|
| 120 | |
|---|