[3784] | 1 | ## Script (Python) "getAccommodationInfo" |
---|
| 2 | ##bind container=container |
---|
| 3 | ##bind context=context |
---|
| 4 | ##bind namespace= |
---|
| 5 | ##bind script=script |
---|
| 6 | ##bind subpath=traverse_subpath |
---|
| 7 | ##parameters=student_id=None |
---|
| 8 | ##title= |
---|
| 9 | ## |
---|
| 10 | # $Id: getAccommodationInfo.py 1726 2007-05-02 06:21:50Z henrik $ |
---|
| 11 | """ |
---|
| 12 | return Info about the current Student |
---|
| 13 | """ |
---|
| 14 | import logging |
---|
| 15 | logger = logging.getLogger('Skins.getAccommodationInfo') |
---|
| 16 | import DateTime |
---|
| 17 | |
---|
| 18 | request = context.REQUEST |
---|
| 19 | mtool = context.portal_membership |
---|
| 20 | wf = context.portal_workflow |
---|
| 21 | member = mtool.getAuthenticatedMember() |
---|
| 22 | member_id = str(member) |
---|
| 23 | path_info = request.get('PATH_INFO').split('/') |
---|
| 24 | |
---|
| 25 | if mtool.isAnonymousUser(): |
---|
| 26 | return None |
---|
| 27 | info = {} |
---|
| 28 | if student_id is None: |
---|
| 29 | requested_id = context.getStudentId() |
---|
| 30 | if requested_id and not context.isStaff() and member_id != requested_id: |
---|
| 31 | logger.info('%s tried to access %s' % (member_id,requested_id)) |
---|
| 32 | return None |
---|
| 33 | elif context.isStaff(): |
---|
| 34 | student_id = requested_id |
---|
| 35 | else: |
---|
| 36 | student_id = member_id |
---|
| 37 | student_record = context.students_catalog.getRecordByKey(student_id) |
---|
| 38 | if student_record is None: |
---|
| 39 | logger.info('%s not found in students_catalog' % student_id) |
---|
| 40 | return None |
---|
| 41 | |
---|
| 42 | info['error'] = None |
---|
| 43 | info['matric_no']=student_record.matric_no |
---|
| 44 | info['jamb_reg_no']=student_record.jamb_reg_no |
---|
| 45 | info['name']=student_record.name |
---|
| 46 | info['email']=student_record.email |
---|
| 47 | info['level']=student_record.level |
---|
| 48 | info['verdict']=getattr(student_record,'verdict','') |
---|
| 49 | review_state = info['review_state'] = student_record.review_state |
---|
| 50 | info['session'] = session = context.getSessionId() |
---|
| 51 | students_object = context.portal_url.getPortalObject().campus.students |
---|
| 52 | student = getattr(students_object, student_id) |
---|
| 53 | info['student_id'] = student_id |
---|
| 54 | info['student'] = student |
---|
| 55 | |
---|
| 56 | booking_allowed = False |
---|
| 57 | |
---|
| 58 | # customize from here |
---|
| 59 | |
---|
| 60 | ekehuan_certificates = ('BARTAPG', |
---|
| 61 | 'BARTAPM', |
---|
| 62 | 'BARTCER', |
---|
| 63 | 'BARTFAA', |
---|
| 64 | 'BARTFAP', |
---|
| 65 | 'BARTSCP', |
---|
| 66 | 'BARTTXT', |
---|
| 67 | 'BARTMAS', |
---|
| 68 | 'BARTTHR', |
---|
| 69 | ) |
---|
| 70 | |
---|
| 71 | new_states = ('cleared_and_validated', |
---|
| 72 | 'school_fee_paid', |
---|
| 73 | 'courses_registered', |
---|
| 74 | 'courses_validated', |
---|
| 75 | ) |
---|
| 76 | |
---|
| 77 | new = student_record.entry_session == session[0] |
---|
| 78 | arrived = student_record.session == session[0] |
---|
| 79 | |
---|
| 80 | level = None |
---|
| 81 | end_level = None |
---|
| 82 | previous = None |
---|
| 83 | |
---|
| 84 | try: |
---|
| 85 | level = int(student_record.level) |
---|
| 86 | except: |
---|
| 87 | logger.info('%s has invalid level %s' % (student_id,student_record.level)) |
---|
| 88 | try: |
---|
| 89 | end_level = int(student_record.end_level) |
---|
| 90 | except: |
---|
| 91 | logger.info('%s has invalid end_level %s' % (student_id,student_record.end_level)) |
---|
| 92 | try: |
---|
| 93 | previous = int(student_record.session) == int(session[0]) - 1 |
---|
| 94 | except: |
---|
| 95 | logger.info('%s has invalid session %s' % (student_id,student_record.session)) |
---|
| 96 | |
---|
| 97 | if level is None or end_level is None or student_record.review_state == 'deactivated': |
---|
| 98 | pass |
---|
| 99 | elif arrived: |
---|
| 100 | if new: |
---|
| 101 | booking_allowed = student_record.review_state in new_states |
---|
| 102 | else: |
---|
| 103 | booking_allowed = not (level % 100) |
---|
| 104 | elif previous: |
---|
| 105 | booking_allowed = student_record.verdict in ('A','B',) |
---|
| 106 | |
---|
| 107 | info['booking_allowed'] = booking_allowed |
---|
| 108 | if not booking_allowed: |
---|
| 109 | info['acco'] = None |
---|
| 110 | info['student_status'] = '' |
---|
| 111 | return info |
---|
| 112 | |
---|
| 113 | acco_id = 'accommodation_' + session[0] |
---|
| 114 | acco = getattr(student,acco_id,None) |
---|
| 115 | info['acco'] = acco |
---|
| 116 | info['acco_id'] = acco_id |
---|
| 117 | bt = 're' |
---|
| 118 | info['maintenance_paid'] = False |
---|
| 119 | if acco is not None: |
---|
| 120 | info['acco_doc'] = acco.getContent() |
---|
| 121 | info['acco_review_state'] = wf.getInfoFor(acco,'review_state',None) |
---|
| 122 | info['maintenance_paid'] = info['acco_review_state'] == "maintenance_fee_paid" |
---|
| 123 | |
---|
| 124 | d = {} |
---|
| 125 | delta = 0 |
---|
| 126 | if previous: |
---|
| 127 | delta = 100 |
---|
| 128 | if new: |
---|
| 129 | bt = 'fr' |
---|
| 130 | elif level + delta < end_level: |
---|
| 131 | bt = 're' |
---|
| 132 | else: |
---|
| 133 | bt = 'fi' |
---|
| 134 | |
---|
| 135 | d['sex'] = 'male' |
---|
| 136 | if student_record.sex: |
---|
| 137 | d['sex'] = 'female' |
---|
| 138 | if student_record.faculty in ('MED','DEN') and level > 400: |
---|
| 139 | bt += "_med" |
---|
| 140 | elif student_record.course in ekehuan_certificates: |
---|
| 141 | bt += "_ekenhuan" |
---|
| 142 | #elif student_record.course in pti_certificates: |
---|
| 143 | # bt += "_pti" |
---|
| 144 | info['sex']=d['sex'] |
---|
| 145 | d['bt'] = bt |
---|
| 146 | student_status = "%(sex)s_%(bt)s" % d |
---|
| 147 | info['student_status'] = student_status |
---|
| 148 | return info |
---|
| 149 | |
---|