[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 2806 2007-11-28 09:00:07Z joachim $ |
---|
| 11 | """ |
---|
| 12 | return Info about the current Student |
---|
| 13 | """ |
---|
[2745] | 14 | import DateTime |
---|
[1185] | 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 |
---|
[1571] | 24 | logger = logging.getLogger('Skins.getStudentFolderInfo') |
---|
[2806] | 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 |
---|
[1185] | 30 | |
---|
| 31 | |
---|
| 32 | info = {} |
---|
| 33 | member_id = str(member) |
---|
[1243] | 34 | #from Products.zdb import set_trace;set_trace() |
---|
[1185] | 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: |
---|
[1571] | 46 | logger.info('%s tried to access %s' % (member_id,requested_id)) |
---|
[1185] | 47 | student_id = member_id |
---|
| 48 | mtool.assertViewable(context) |
---|
| 49 | break |
---|
| 50 | student_id = member_id |
---|
| 51 | break |
---|
[1431] | 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) |
---|
[2806] | 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: |
---|
[1185] | 61 | return None |
---|
[2806] | 62 | |
---|
[1185] | 63 | #from Products.zdb import set_trace;set_trace() |
---|
| 64 | for field in context.students_catalog.schema(): |
---|
[2806] | 65 | info[field] = getattr(student_record,field) |
---|
[1359] | 66 | |
---|
[1871] | 67 | #res = context.portal_catalog(portal_type='Student',id = student_id) |
---|
| 68 | #if res: |
---|
| 69 | # info['review_state'] = res[0].review_state |
---|
| 70 | |
---|
[2806] | 71 | #info['review_state'] = context.getStudentReviewState() |
---|
[1871] | 72 | |
---|
[1422] | 73 | info['session'] = False |
---|
[2806] | 74 | if student_record.matric_no: |
---|
| 75 | res = context.results_import(matric_no = student_record.matric_no) |
---|
[1422] | 76 | if res: |
---|
| 77 | info['session'] = True |
---|
| 78 | |
---|
[2806] | 79 | info['base_info'] = context.getFormattedStudentEntry(student_record) |
---|
[1472] | 80 | |
---|
[1185] | 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', |
---|
[1243] | 93 | 'PaymentsFolder': 'payments_view', |
---|
[1185] | 94 | } |
---|
[2745] | 95 | #logger.info("before search") |
---|
| 96 | starttime = DateTime.DateTime().timeTime() |
---|
[2806] | 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 | starttime = DateTime.DateTime().timeTime() |
---|
| 121 | #sos = context.portal_catalog(container_path=student_path_root) |
---|
| 122 | student_obj = getattr(students_folder,student_id) |
---|
| 123 | subobjects = student_obj.objectValues() |
---|
[2745] | 124 | logger.info("searchtime %f" % (DateTime.DateTime().timeTime() - starttime)) |
---|
| 125 | starttime = DateTime.DateTime().timeTime() |
---|
[2806] | 126 | for subobject in subobjects: |
---|
[1185] | 127 | row = {} |
---|
[2806] | 128 | row['id'] = subobject.getId() |
---|
| 129 | row['title'] = subobject.Title |
---|
| 130 | url = row['url'] = subobject.absolute_url() |
---|
| 131 | row['type'] = subobject.portal_type |
---|
| 132 | review_state = row['review_state'] = wf.getInfoFor(subobject,'review_state',None) |
---|
[1472] | 133 | row['is_editable'] = (is_student and review_state == "opened") or is_sectionofficer |
---|
[2806] | 134 | sv_link = s_view_links.get(subobject.portal_type,None) or "waeup_document_view" |
---|
[1185] | 135 | row['s_view_link'] = "%s/%s" % (url,sv_link) |
---|
[2806] | 136 | se_link = s_edit_links.get(subobject.portal_type,None) |
---|
[1185] | 137 | row['s_edit_link'] = None |
---|
| 138 | if se_link: |
---|
| 139 | row['s_edit_link'] = "%s/%s" % (url,se_link) |
---|
| 140 | row['display'] = review_state in ('opened','closed','bed_reserved','maintenance_fee_paid',)\ |
---|
[2806] | 141 | and subobject.portal_type not in ('StudentPume','StudentAccommodation','PaymentsFolder',) or\ |
---|
| 142 | subobject.portal_type == 'StudentStudyCourse' |
---|
[1185] | 143 | items.append(row) |
---|
[2745] | 144 | logger.info("listtime %f" % (DateTime.DateTime().timeTime() - starttime)) |
---|
[2477] | 145 | items.sort(cmp=lambda x,y: cmp( x['title'],y['title'])) |
---|
[1185] | 146 | info['items'] = items |
---|
[1214] | 147 | info['member'] = member |
---|
[1185] | 148 | return info |
---|
[1258] | 149 | |
---|