[5781] | 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 | try:
|
---|
| 73 | level = int(student_record.level)
|
---|
| 74 | except:
|
---|
| 75 | logger.info('%s has invalid level %s' % (student_id,student_record.level))
|
---|
| 76 | info['acco'] = None
|
---|
| 77 | info['booking_allowed'] = False
|
---|
| 78 | info['student_status'] = ''
|
---|
| 79 | return info
|
---|
| 80 |
|
---|
| 81 | if review_state in ('cleared_and_validated','school_fee_paid','courses_registered', 'courses_validated',) and student_record.session == session[0]:
|
---|
| 82 | info['booking_allowed'] = True
|
---|
| 83 | info['online_payment'] = True
|
---|
| 84 | # returning student can also book without having paid the school fee (see ticket #29)
|
---|
| 85 | #elif review_state == 'returning' and int(student_record.session)+1 == int(session[0]):
|
---|
| 86 | # info['booking_allowed'] = True
|
---|
| 87 | # info['online_payment'] = True
|
---|
| 88 | else:
|
---|
| 89 | info['acco'] = None
|
---|
| 90 | info['booking_allowed'] = False
|
---|
| 91 | info['student_status'] = ''
|
---|
[5788] | 92 | #logger.info('%s: not eligible' % (student_id))
|
---|
[5781] | 93 | return info
|
---|
| 94 |
|
---|
| 95 | d = {}
|
---|
| 96 | d['sex'] = 'male'
|
---|
| 97 | #d['bt'] = 'all'
|
---|
| 98 | if student_record.sex:
|
---|
| 99 | d['sex'] = 'female'
|
---|
[7131] | 100 |
|
---|
[5781] | 101 | if level == 100:
|
---|
| 102 | bt = 'fr'
|
---|
| 103 | else:
|
---|
| 104 | bt = 're'
|
---|
| 105 | if student_record.faculty in ('SSE'):
|
---|
| 106 | bt += "_sse"
|
---|
| 107 | d['bt'] = bt
|
---|
| 108 |
|
---|
| 109 | info['sex']=d['sex']
|
---|
| 110 | student_status = "%(sex)s_%(bt)s" % d
|
---|
| 111 | info['student_status'] = student_status
|
---|
| 112 |
|
---|
| 113 | # customize end
|
---|
| 114 |
|
---|
| 115 | acco_id = student_id + '|' + session[0]
|
---|
| 116 | info['acco_id'] = acco_id
|
---|
| 117 |
|
---|
| 118 | if booking_disabled:
|
---|
| 119 | info['booking_disabled'] = True
|
---|
| 120 | #logger.info('%s: %s eligible but booking disabled' % (student_id,student_status))
|
---|
| 121 |
|
---|
| 122 | accommodation_record = context.accommodation_catalog.getRecordByKey(acco_id)
|
---|
| 123 | if accommodation_record is None:
|
---|
| 124 | return info
|
---|
| 125 |
|
---|
| 126 | info['booking_allowed'] = False
|
---|
| 127 | info['acco_res_date'] = accommodation_record.acco_res_date
|
---|
| 128 | info['acco_res_sc_pin'] = accommodation_record.acco_res_sc_pin
|
---|
| 129 | info['acco_maint_fee'] = accommodation_record.acco_maint_fee
|
---|
| 130 | info['acco_maint_code'] = accommodation_record.acco_maint_code
|
---|
| 131 | info['bed'] = accommodation_record.bed
|
---|
| 132 | info['session'] = accommodation_record.session
|
---|
| 133 | info['maintenance_paid'] = accommodation_record.reservation_status == 'maintenance_fee_paid'
|
---|
| 134 |
|
---|
| 135 | return info
|
---|