## Script (Python) "getAccommodationInfo" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters=student_id=None ##title= ## # $Id: getAccommodationInfo.py 1726 2007-05-02 06:21:50Z henrik $ """ return Info about the current Student """ import logging logger = logging.getLogger('Skins.getAccommodationInfo') import DateTime 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 ekehuan_certificates = ('BARTAPG', 'BARTAPM', 'BARTCER', 'BARTFAA', 'BARTFAP', 'BARTSCP', 'BARTTXT', 'BARTMAS', 'BARTTHR', ) #pti_certificates = ('BENGIEP', # 'BENGGCPP', # 'BENGEEP', # 'BENGGEP', # 'BENGPEP', # 'BENGMEP', # ) new_states = ('cleared_and_validated', 'school_fee_paid', 'courses_registered', 'courses_validated', ) 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 booking_allowed = False new = student_record.entry_session == session[0] arrived = student_record.session == session[0] previous = int(student_record.session) == int(session[0]) - 1 level = None end_level = None try: level = int(student_record.level) except ValueError: logger.info('%s has invalid level %s' % (member_id,student_record.level)) try: end_level = int(student_record.end_level) except ValueError: logger.info('%s has invalid end_level %s' % (member_id,student_record.end_level)) if level is None or end_level is None or student_record.review_state == 'deactivated': 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['acco'] = None info['student_status'] = '' return info acco_id = 'accommodation_' + session[0] acco = getattr(student,acco_id,None) info['acco'] = acco info['acco_id'] = acco_id bt = 're' info['maintenance_paid'] = False if acco is not None: info['acco_doc'] = acco.getContent() info['acco_review_state'] = wf.getInfoFor(acco,'review_state',None) info['maintenance_paid'] = info['acco_review_state'] == "maintenance_fee_paid" d = {} delta = 0 if previous: delta = 100 if new: bt = 'fr' elif level + delta < end_level: bt = 're' else: bt = 'fi' # else: # res = context.portal_catalog(portal_type = "Certificate", id = student_record.course) # if res: # c_brain = res[0] # #from Products.zdb import set_trace; set_trace() # certificate = c_brain.getObject().getContent() # try: # certlevel = int(certificate.end_level) # except: # info["error"] = '"no end_level for","%s"' % c_brain.getId # return info # try: # studentlevel = int(student_record.level) # except: # info["error"] = '"no level for","%s"' % student_record.getId # return info # if studentlevel >= certlevel: # 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 return info