## Script (Python) "getStudentInfo" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters=with_items=None ##title= ## # $Id: getStudentFolderInfo.py 1431 2007-02-17 15:42:31Z henrik $ """ return Info about the current Student """ request = context.REQUEST form = request.form fget = form.get wf = context.portal_workflow mtool = context.portal_membership member = mtool.getAuthenticatedMember() path_info = request.get('PATH_INFO').split('/') import logging logger = logging.getLogger('Student.Info') info = {} member_id = str(member) #from Products.zdb import set_trace;set_trace() is_student = info['is_student'] = context.isStudent() is_staff = info['is_staff'] = context.isStaff() is_sectionofficer = info['is_sectionofficer'] = context.isSectionOfficer() while True: if mtool.isAnonymousUser(): return None requested_id = context.getStudentId() if not is_student and requested_id: student_id = requested_id break if member_id != requested_id: logger.info('"%s", "tried to access", "%s"' % (member_id,requested_id)) student_id = member_id mtool.assertViewable(context) break student_id = member_id break student_path_root = "%s/campus/students/%s" % (context.portal_url.getPortalPath(),student_id) student_path = "%s/campus/students/%s" % (context.portal_url(),student_id) res = context.students_catalog(id = student_id) if not res: return None st_brain = res[0] #from Products.zdb import set_trace;set_trace() for field in context.students_catalog.schema(): info[field] = getattr(st_brain,field) res = context.portal_catalog(portal_type='Student',id = student_id) if res: info['review_state'] = res[0].review_state info['session'] = False if st_brain.matric_no: res = context.results_import(matric_no = st_brain.matric_no) if res: info['session'] = True info['id'] = student_id items = [] s_edit_links = {'StudentApplication': 'application_edit_form', 'StudentAccommodation': 'reserve_accommodation', 'StudentClearance': 'clearance_edit_form', 'StudentPersonal': 'personal_edit_form', } s_view_links = {'StudentApplication': 'application_view', 'StudentAccommodation': 'accommodation_view', 'StudentClearance': 'clearance_view', 'StudentPersonal': 'personal_view', 'StudentStudyCourse': 'study_course_view', 'PaymentsFolder': 'payments_view', 'StudentPume': 'pume_view', } sos = context.portal_catalog(container_path=student_path_root) for so in sos: row = {} row['id'] = so.getId row['title'] = so.Title url = row['url'] = "%s/%s" % (student_path,so.getId) row['type'] = so.portal_type review_state = row['review_state'] = so.review_state row['is_editable'] = (is_student and review_state == "opened") or not is_student sv_link = s_view_links.get(so.portal_type,None) or "waeup_document_view" row['s_view_link'] = "%s/%s" % (url,sv_link) se_link = s_edit_links.get(so.portal_type,None) row['s_edit_link'] = None if se_link: row['s_edit_link'] = "%s/%s" % (url,se_link) row['display'] = review_state in ('opened','closed','bed_reserved','maintenance_fee_paid',)\ and so.portal_type not in ('StudentPume','StudentAccommodation','PaymentsFolder',) or\ so.portal_type == 'StudentStudyCourse' items.append(row) info['items'] = items info['member'] = member return info