[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 2837 2007-12-01 12:42:28Z joachim $ |
---|
| 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 | info = {} |
---|
| 38 | member_id = str(member) |
---|
[1243] | 39 | #from Products.zdb import set_trace;set_trace() |
---|
[1185] | 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: |
---|
[1571] | 51 | logger.info('%s tried to access %s' % (member_id,requested_id)) |
---|
[1185] | 52 | student_id = member_id |
---|
| 53 | mtool.assertViewable(context) |
---|
| 54 | break |
---|
| 55 | student_id = member_id |
---|
| 56 | break |
---|
[1431] | 57 | student_path_root = "%s/campus/students/%s" % (context.portal_url.getPortalPath(),student_id) |
---|
| 58 | student_path = "%s/campus/students/%s" % (context.portal_url(),student_id) |
---|
[2806] | 59 | students_folder = context.portal_url.getPortalObject().campus.students |
---|
| 60 | # res = context.students_catalog(id = student_id) |
---|
| 61 | # if not res: |
---|
| 62 | # return None |
---|
| 63 | # student_record = res[0] |
---|
| 64 | student_record = context.students_catalog.getRecordByKey(student_id) |
---|
| 65 | if student_record is None: |
---|
[1185] | 66 | return None |
---|
[2831] | 67 | |
---|
[1185] | 68 | #from Products.zdb import set_trace;set_trace() |
---|
| 69 | for field in context.students_catalog.schema(): |
---|
[2806] | 70 | info[field] = getattr(student_record,field) |
---|
[1359] | 71 | |
---|
[1871] | 72 | #res = context.portal_catalog(portal_type='Student',id = student_id) |
---|
| 73 | #if res: |
---|
| 74 | # info['review_state'] = res[0].review_state |
---|
| 75 | |
---|
[2806] | 76 | #info['review_state'] = context.getStudentReviewState() |
---|
[1871] | 77 | |
---|
[1422] | 78 | info['session'] = False |
---|
[2806] | 79 | if student_record.matric_no: |
---|
| 80 | res = context.results_import(matric_no = student_record.matric_no) |
---|
[1422] | 81 | if res: |
---|
| 82 | info['session'] = True |
---|
| 83 | |
---|
[2831] | 84 | info['base_info'] = context.getFormattedStudentEntry(student_record) |
---|
[1472] | 85 | |
---|
[1185] | 86 | info['id'] = student_id |
---|
| 87 | items = [] |
---|
| 88 | s_edit_links = {'StudentApplication': 'application_edit_form', |
---|
| 89 | 'StudentAccommodation': 'reserve_accommodation', |
---|
| 90 | 'StudentClearance': 'clearance_edit_form', |
---|
| 91 | 'StudentPersonal': 'personal_edit_form', |
---|
| 92 | } |
---|
| 93 | s_view_links = {'StudentApplication': 'application_view', |
---|
| 94 | 'StudentAccommodation': 'accommodation_view', |
---|
| 95 | 'StudentClearance': 'clearance_view', |
---|
| 96 | 'StudentPersonal': 'personal_view', |
---|
| 97 | 'StudentStudyCourse': 'study_course_view', |
---|
[1243] | 98 | 'PaymentsFolder': 'payments_view', |
---|
[1185] | 99 | } |
---|
[2745] | 100 | #logger.info("before search") |
---|
[2831] | 101 | #starttime = DateTime.DateTime().timeTime() |
---|
[2806] | 102 | #sos = context.portal_catalog(container_path=student_path_root) |
---|
| 103 | # query = Eq('container_path',student_path_root) |
---|
| 104 | # sos = aq_portal(query) |
---|
| 105 | # logger.info("searchtime %f" % (DateTime.DateTime().timeTime() - starttime)) |
---|
| 106 | # starttime = DateTime.DateTime().timeTime() |
---|
| 107 | # for so in sos: |
---|
| 108 | # row = {} |
---|
| 109 | # row['id'] = so.getId |
---|
| 110 | # row['title'] = so.Title |
---|
| 111 | # url = row['url'] = "%s/%s" % (student_path,so.getId) |
---|
| 112 | # row['type'] = so.portal_type |
---|
| 113 | # review_state = row['review_state'] = so.review_state |
---|
| 114 | # row['is_editable'] = (is_student and review_state == "opened") or is_sectionofficer |
---|
| 115 | # sv_link = s_view_links.get(so.portal_type,None) or "waeup_document_view" |
---|
| 116 | # row['s_view_link'] = "%s/%s" % (url,sv_link) |
---|
| 117 | # se_link = s_edit_links.get(so.portal_type,None) |
---|
| 118 | # row['s_edit_link'] = None |
---|
| 119 | # if se_link: |
---|
| 120 | # row['s_edit_link'] = "%s/%s" % (url,se_link) |
---|
| 121 | # row['display'] = review_state in ('opened','closed','bed_reserved','maintenance_fee_paid',)\ |
---|
| 122 | # and so.portal_type not in ('StudentPume','StudentAccommodation','PaymentsFolder',) or\ |
---|
| 123 | # so.portal_type == 'StudentStudyCourse' |
---|
| 124 | # items.append(row) |
---|
| 125 | #sos = context.portal_catalog(container_path=student_path_root) |
---|
| 126 | student_obj = getattr(students_folder,student_id) |
---|
| 127 | subobjects = student_obj.objectValues() |
---|
[2831] | 128 | #logger.info("searchtime %f" % (DateTime.DateTime().timeTime() - starttime)) |
---|
| 129 | #starttime = DateTime.DateTime().timeTime() |
---|
[2806] | 130 | for subobject in subobjects: |
---|
[1185] | 131 | row = {} |
---|
[2806] | 132 | row['id'] = subobject.getId() |
---|
[2837] | 133 | row['title'] = subobject.Title() |
---|
[2806] | 134 | url = row['url'] = subobject.absolute_url() |
---|
| 135 | row['type'] = subobject.portal_type |
---|
| 136 | review_state = row['review_state'] = wf.getInfoFor(subobject,'review_state',None) |
---|
[1472] | 137 | row['is_editable'] = (is_student and review_state == "opened") or is_sectionofficer |
---|
[2806] | 138 | sv_link = s_view_links.get(subobject.portal_type,None) or "waeup_document_view" |
---|
[1185] | 139 | row['s_view_link'] = "%s/%s" % (url,sv_link) |
---|
[2806] | 140 | se_link = s_edit_links.get(subobject.portal_type,None) |
---|
[1185] | 141 | row['s_edit_link'] = None |
---|
| 142 | if se_link: |
---|
| 143 | row['s_edit_link'] = "%s/%s" % (url,se_link) |
---|
| 144 | row['display'] = review_state in ('opened','closed','bed_reserved','maintenance_fee_paid',)\ |
---|
[2806] | 145 | and subobject.portal_type not in ('StudentPume','StudentAccommodation','PaymentsFolder',) or\ |
---|
| 146 | subobject.portal_type == 'StudentStudyCourse' |
---|
[1185] | 147 | items.append(row) |
---|
[2831] | 148 | #logger.info("listtime %f" % (DateTime.DateTime().timeTime() - starttime)) |
---|
[2837] | 149 | #set_trace() |
---|
[2477] | 150 | items.sort(cmp=lambda x,y: cmp( x['title'],y['title'])) |
---|
[1185] | 151 | info['items'] = items |
---|
[1214] | 152 | info['member'] = member |
---|
[1185] | 153 | return info |
---|
[1258] | 154 | |
---|