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