## Script (Python) "getAccommodationStatus" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters=student_id=None ##title= ## # $Id: getAccommodationStatus.py 5616 2010-12-27 10:18:18Z henrik $ """ return Info about the current Student """ try: from Products.zdb import set_trace except: def set_trace(): pass import logging logger = logging.getLogger('Skins.getAccommodationStatus') import DateTime pprops = context.portal_properties booking_disabled = not pprops.enable_acco_booking request = context.REQUEST mtool = context.portal_membership wf = context.portal_workflow member = mtool.getAuthenticatedMember() member_id = str(member) path_info = request.get('PATH_INFO').split('/') if mtool.isAnonymousUser(): return None info = {} if student_id is None: requested_id = context.getStudentId() if requested_id and not context.isStaff() and member_id != requested_id: logger.info('%s tried to access %s' % (member_id,requested_id)) return None elif context.isStaff(): student_id = requested_id else: student_id = member_id student_record = context.students_catalog.getRecordByKey(student_id) if student_record is None: logger.info('%s not found in students_catalog' % student_id) return None info['error'] = None info['matric_no']=student_record.matric_no info['jamb_reg_no']=student_record.jamb_reg_no info['name']=student_record.name info['email']=student_record.email info['level']=student_record.level info['verdict']=getattr(student_record,'verdict','') review_state = info['review_state'] = student_record.review_state info['session'] = session = context.getSessionId() students_object = context.portal_url.getPortalObject().campus.students student = getattr(students_object, student_id) info['student_id'] = student_id info['student'] = student # do not change these settings! booking_allowed = False info['booking_disabled'] = False # customize from here ekehuan_certificates = ('BARTAPG', 'BARTAPM', 'BARTCER', 'BARTFAA', 'BARTFAP', 'BARTSCP', 'BARTTXT', 'BARTMAS', 'BARTTHR', ) new_states = ('cleared_and_validated', 'school_fee_paid', 'courses_registered', 'courses_validated', ) new = None arrived = None try: new = int(student_record.entry_session) == int(session[0]) except: logger.info('%s has invalid entry_session %s' % (student_id,student_record.entry_session)) try: arrived = int(student_record.session) == int(session[0]) except: logger.info('%s has invalid session %s' % (student_id,student_record.session)) level = None end_level = None previous = None try: level = int(student_record.level) except: logger.info('%s has invalid level %s' % (student_id,student_record.level)) try: end_level = int(student_record.end_level) except: logger.info('%s has invalid end_level %s' % (student_id,student_record.end_level)) try: previous = int(student_record.session) == int(session[0]) - 1 except: logger.info('%s has invalid session %s' % (student_id,student_record.session)) if level is None or end_level is None or student_record.review_state in ('deactivated','graduated'): pass elif arrived: if new: booking_allowed = student_record.review_state in new_states else: booking_allowed = not (level % 100) elif previous: booking_allowed = student_record.verdict in ('A','B',) info['booking_allowed'] = booking_allowed if not booking_allowed: info['student_status'] = '' #info['new'] = new logger.info('%s: not eligible' % (student_id)) return info d = {} delta = 0 if previous: delta = 100 if new: bt = 'fr' elif level + delta < end_level: bt = 're' else: bt = 'fi' d['sex'] = 'male' if student_record.sex: d['sex'] = 'female' if student_record.faculty in ('MED','DEN') and level > 400: bt += "_med" elif student_record.course in ekehuan_certificates: bt += "_ekenhuan" #elif student_record.course in pti_certificates: # bt += "_pti" info['sex']=d['sex'] d['bt'] = bt student_status = "%(sex)s_%(bt)s" % d info['student_status'] = student_status # customize end acco_id = student_id + '|' + session[0] info['acco_id'] = acco_id if booking_disabled: info['booking_disabled'] = True #logger.info('%s: %s eligible but booking disabled' % (student_id,student_status)) accommodation_record = context.accommodation_catalog.getRecordByKey(acco_id) if accommodation_record is None: return info info['booking_allowed'] = False info['acco_res_date'] = accommodation_record.acco_res_date info['acco_res_sc_pin'] = accommodation_record.acco_res_sc_pin info['acco_maint_fee'] = accommodation_record.acco_maint_fee info['student_status'] = accommodation_record.student_status info['bed'] = accommodation_record.bed info['session'] = accommodation_record.session return info