## Script (Python) "getStudentFolderInfo" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters=with_items=None ##title= ## # $Id: getStudentFolderInfo.py 2831 2007-11-30 11:46:03Z henrik $ """ return Info about the current Student """ import DateTime 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('Skins.getStudentFolderInfo') from Products.AdvancedQuery import Eq, Between, Le,In try: aq_portal = context.portal_catalog.evalAdvancedQuery except: aq_portal = context.portal_catalog_real.evalAdvancedQuery 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) students_folder = context.portal_url.getPortalObject().campus.students # res = context.students_catalog(id = student_id) # if not res: # return None # student_record = res[0] student_record = context.students_catalog.getRecordByKey(student_id) if student_record is None: return None #from Products.zdb import set_trace;set_trace() for field in context.students_catalog.schema(): info[field] = getattr(student_record,field) #res = context.portal_catalog(portal_type='Student',id = student_id) #if res: # info['review_state'] = res[0].review_state #info['review_state'] = context.getStudentReviewState() info['session'] = False if student_record.matric_no: res = context.results_import(matric_no = student_record.matric_no) if res: info['session'] = True info['base_info'] = context.getFormattedStudentEntry(student_record) 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', } #logger.info("before search") #starttime = DateTime.DateTime().timeTime() #sos = context.portal_catalog(container_path=student_path_root) # query = Eq('container_path',student_path_root) # sos = aq_portal(query) # logger.info("searchtime %f" % (DateTime.DateTime().timeTime() - starttime)) # starttime = DateTime.DateTime().timeTime() # 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 is_sectionofficer # 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) #sos = context.portal_catalog(container_path=student_path_root) student_obj = getattr(students_folder,student_id) subobjects = student_obj.objectValues() #logger.info("searchtime %f" % (DateTime.DateTime().timeTime() - starttime)) #starttime = DateTime.DateTime().timeTime() for subobject in subobjects: row = {} row['id'] = subobject.getId() row['title'] = subobject.Title url = row['url'] = subobject.absolute_url() row['type'] = subobject.portal_type review_state = row['review_state'] = wf.getInfoFor(subobject,'review_state',None) row['is_editable'] = (is_student and review_state == "opened") or is_sectionofficer sv_link = s_view_links.get(subobject.portal_type,None) or "waeup_document_view" row['s_view_link'] = "%s/%s" % (url,sv_link) se_link = s_edit_links.get(subobject.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 subobject.portal_type not in ('StudentPume','StudentAccommodation','PaymentsFolder',) or\ subobject.portal_type == 'StudentStudyCourse' items.append(row) #logger.info("listtime %f" % (DateTime.DateTime().timeTime() - starttime)) items.sort(cmp=lambda x,y: cmp( x['title'],y['title'])) info['items'] = items info['member'] = member return info