[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 | |
---|
[4007] | 18 | booking_disabled = True |
---|
[3863] | 19 | |
---|
[3784] | 20 | request = context.REQUEST |
---|
| 21 | mtool = context.portal_membership |
---|
| 22 | wf = context.portal_workflow |
---|
| 23 | member = mtool.getAuthenticatedMember() |
---|
| 24 | member_id = str(member) |
---|
| 25 | path_info = request.get('PATH_INFO').split('/') |
---|
| 26 | |
---|
| 27 | if mtool.isAnonymousUser(): |
---|
| 28 | return None |
---|
| 29 | info = {} |
---|
| 30 | if student_id is None: |
---|
| 31 | requested_id = context.getStudentId() |
---|
| 32 | if requested_id and not context.isStaff() and member_id != requested_id: |
---|
| 33 | logger.info('%s tried to access %s' % (member_id,requested_id)) |
---|
| 34 | return None |
---|
| 35 | elif context.isStaff(): |
---|
| 36 | student_id = requested_id |
---|
| 37 | else: |
---|
| 38 | student_id = member_id |
---|
| 39 | student_record = context.students_catalog.getRecordByKey(student_id) |
---|
| 40 | if student_record is None: |
---|
| 41 | logger.info('%s not found in students_catalog' % student_id) |
---|
| 42 | return None |
---|
| 43 | |
---|
| 44 | info['error'] = None |
---|
| 45 | info['matric_no']=student_record.matric_no |
---|
| 46 | info['jamb_reg_no']=student_record.jamb_reg_no |
---|
| 47 | info['name']=student_record.name |
---|
| 48 | info['email']=student_record.email |
---|
| 49 | info['level']=student_record.level |
---|
| 50 | info['verdict']=getattr(student_record,'verdict','') |
---|
| 51 | review_state = info['review_state'] = student_record.review_state |
---|
| 52 | info['session'] = session = context.getSessionId() |
---|
| 53 | students_object = context.portal_url.getPortalObject().campus.students |
---|
| 54 | student = getattr(students_object, student_id) |
---|
| 55 | info['student_id'] = student_id |
---|
| 56 | info['student'] = student |
---|
| 57 | |
---|
[4007] | 58 | # do not change these settings! |
---|
| 59 | |
---|
[3784] | 60 | booking_allowed = False |
---|
[4007] | 61 | info['booking_disabled'] = False |
---|
[3784] | 62 | |
---|
| 63 | # customize from here |
---|
| 64 | |
---|
| 65 | ekehuan_certificates = ('BARTAPG', |
---|
| 66 | 'BARTAPM', |
---|
| 67 | 'BARTCER', |
---|
| 68 | 'BARTFAA', |
---|
| 69 | 'BARTFAP', |
---|
| 70 | 'BARTSCP', |
---|
| 71 | 'BARTTXT', |
---|
| 72 | 'BARTMAS', |
---|
| 73 | 'BARTTHR', |
---|
| 74 | ) |
---|
| 75 | |
---|
| 76 | new_states = ('cleared_and_validated', |
---|
| 77 | 'school_fee_paid', |
---|
| 78 | 'courses_registered', |
---|
| 79 | 'courses_validated', |
---|
| 80 | ) |
---|
[4007] | 81 | new = None |
---|
| 82 | arrived = None |
---|
[3784] | 83 | |
---|
[3960] | 84 | try: |
---|
| 85 | new = int(student_record.entry_session) == int(session[0]) |
---|
| 86 | except: |
---|
| 87 | logger.info('%s has invalid entry_session %s' % (student_id,student_record.entry_session)) |
---|
| 88 | try: |
---|
| 89 | arrived = int(student_record.session) == int(session[0]) |
---|
| 90 | except: |
---|
| 91 | logger.info('%s has invalid session %s' % (student_id,student_record.session)) |
---|
[4007] | 92 | |
---|
[3784] | 93 | level = None |
---|
| 94 | end_level = None |
---|
| 95 | previous = None |
---|
| 96 | |
---|
| 97 | try: |
---|
| 98 | level = int(student_record.level) |
---|
| 99 | except: |
---|
| 100 | logger.info('%s has invalid level %s' % (student_id,student_record.level)) |
---|
| 101 | try: |
---|
| 102 | end_level = int(student_record.end_level) |
---|
| 103 | except: |
---|
| 104 | logger.info('%s has invalid end_level %s' % (student_id,student_record.end_level)) |
---|
| 105 | try: |
---|
| 106 | previous = int(student_record.session) == int(session[0]) - 1 |
---|
| 107 | except: |
---|
| 108 | logger.info('%s has invalid session %s' % (student_id,student_record.session)) |
---|
| 109 | |
---|
[3985] | 110 | if level is None or end_level is None or student_record.review_state in ('deactivated','graduated'): |
---|
[3784] | 111 | pass |
---|
| 112 | elif arrived: |
---|
| 113 | if new: |
---|
| 114 | booking_allowed = student_record.review_state in new_states |
---|
| 115 | else: |
---|
[3985] | 116 | booking_allowed = not (level % 100) |
---|
[3784] | 117 | elif previous: |
---|
| 118 | booking_allowed = student_record.verdict in ('A','B',) |
---|
| 119 | |
---|
| 120 | info['booking_allowed'] = booking_allowed |
---|
| 121 | if not booking_allowed: |
---|
| 122 | info['acco'] = None |
---|
| 123 | info['student_status'] = '' |
---|
[4007] | 124 | logger.info('%s: not eligible' % (student_id)) |
---|
[3784] | 125 | return info |
---|
| 126 | |
---|
| 127 | d = {} |
---|
| 128 | delta = 0 |
---|
| 129 | if previous: |
---|
| 130 | delta = 100 |
---|
| 131 | if new: |
---|
| 132 | bt = 'fr' |
---|
| 133 | elif level + delta < end_level: |
---|
| 134 | bt = 're' |
---|
| 135 | else: |
---|
| 136 | bt = 'fi' |
---|
| 137 | d['sex'] = 'male' |
---|
| 138 | if student_record.sex: |
---|
| 139 | d['sex'] = 'female' |
---|
| 140 | if student_record.faculty in ('MED','DEN') and level > 400: |
---|
| 141 | bt += "_med" |
---|
| 142 | elif student_record.course in ekehuan_certificates: |
---|
| 143 | bt += "_ekenhuan" |
---|
| 144 | #elif student_record.course in pti_certificates: |
---|
| 145 | # bt += "_pti" |
---|
| 146 | info['sex']=d['sex'] |
---|
| 147 | d['bt'] = bt |
---|
| 148 | student_status = "%(sex)s_%(bt)s" % d |
---|
| 149 | info['student_status'] = student_status |
---|
[4007] | 150 | |
---|
| 151 | # customize end |
---|
| 152 | |
---|
| 153 | acco_id = 'accommodation_' + session[0] |
---|
| 154 | acco = getattr(student,acco_id,None) |
---|
| 155 | info['acco'] = acco |
---|
| 156 | info['acco_id'] = acco_id |
---|
| 157 | info['maintenance_paid'] = False |
---|
| 158 | if acco is not None: |
---|
| 159 | info['acco_doc'] = acco.getContent() |
---|
| 160 | info['acco_review_state'] = wf.getInfoFor(acco,'review_state',None) |
---|
| 161 | info['maintenance_paid'] = info['acco_review_state'] == "maintenance_fee_paid" |
---|
| 162 | elif booking_disabled: |
---|
| 163 | info['booking_allowed'] = False |
---|
| 164 | info['booking_disabled'] = True |
---|
| 165 | logger.info('%s: %s eligible but booking disabled' % (student_id,student_status)) |
---|
| 166 | |
---|
[3784] | 167 | return info |
---|