[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 | |
---|
[3863] | 18 | booking_disabled = False |
---|
| 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 | |
---|
| 58 | booking_allowed = False |
---|
| 59 | |
---|
| 60 | # customize from here |
---|
| 61 | |
---|
| 62 | ekehuan_certificates = ('BARTAPG', |
---|
| 63 | 'BARTAPM', |
---|
| 64 | 'BARTCER', |
---|
| 65 | 'BARTFAA', |
---|
| 66 | 'BARTFAP', |
---|
| 67 | 'BARTSCP', |
---|
| 68 | 'BARTTXT', |
---|
| 69 | 'BARTMAS', |
---|
| 70 | 'BARTTHR', |
---|
| 71 | ) |
---|
| 72 | |
---|
| 73 | new_states = ('cleared_and_validated', |
---|
| 74 | 'school_fee_paid', |
---|
| 75 | 'courses_registered', |
---|
| 76 | 'courses_validated', |
---|
| 77 | ) |
---|
| 78 | |
---|
| 79 | new = student_record.entry_session == session[0] |
---|
| 80 | arrived = student_record.session == session[0] |
---|
| 81 | |
---|
| 82 | level = None |
---|
| 83 | end_level = None |
---|
| 84 | previous = None |
---|
| 85 | |
---|
| 86 | try: |
---|
| 87 | level = int(student_record.level) |
---|
| 88 | except: |
---|
| 89 | logger.info('%s has invalid level %s' % (student_id,student_record.level)) |
---|
| 90 | try: |
---|
| 91 | end_level = int(student_record.end_level) |
---|
| 92 | except: |
---|
| 93 | logger.info('%s has invalid end_level %s' % (student_id,student_record.end_level)) |
---|
| 94 | try: |
---|
| 95 | previous = int(student_record.session) == int(session[0]) - 1 |
---|
| 96 | except: |
---|
| 97 | logger.info('%s has invalid session %s' % (student_id,student_record.session)) |
---|
| 98 | |
---|
| 99 | if level is None or end_level is None or student_record.review_state == 'deactivated': |
---|
| 100 | pass |
---|
| 101 | elif arrived: |
---|
| 102 | if new: |
---|
| 103 | booking_allowed = student_record.review_state in new_states |
---|
| 104 | else: |
---|
| 105 | booking_allowed = not (level % 100) |
---|
| 106 | elif previous: |
---|
| 107 | booking_allowed = student_record.verdict in ('A','B',) |
---|
| 108 | |
---|
| 109 | info['booking_allowed'] = booking_allowed |
---|
| 110 | if not booking_allowed: |
---|
| 111 | info['acco'] = None |
---|
| 112 | info['student_status'] = '' |
---|
| 113 | return info |
---|
| 114 | |
---|
| 115 | acco_id = 'accommodation_' + session[0] |
---|
| 116 | acco = getattr(student,acco_id,None) |
---|
| 117 | info['acco'] = acco |
---|
| 118 | info['acco_id'] = acco_id |
---|
| 119 | bt = 're' |
---|
| 120 | info['maintenance_paid'] = False |
---|
| 121 | if acco is not None: |
---|
| 122 | info['acco_doc'] = acco.getContent() |
---|
| 123 | info['acco_review_state'] = wf.getInfoFor(acco,'review_state',None) |
---|
| 124 | info['maintenance_paid'] = info['acco_review_state'] == "maintenance_fee_paid" |
---|
[3863] | 125 | elif booking_disabled: |
---|
| 126 | info['booking_allowed'] = False |
---|
[3784] | 127 | |
---|
| 128 | d = {} |
---|
| 129 | delta = 0 |
---|
| 130 | if previous: |
---|
| 131 | delta = 100 |
---|
| 132 | if new: |
---|
| 133 | bt = 'fr' |
---|
| 134 | elif level + delta < end_level: |
---|
| 135 | bt = 're' |
---|
| 136 | else: |
---|
| 137 | bt = 'fi' |
---|
| 138 | |
---|
| 139 | d['sex'] = 'male' |
---|
| 140 | if student_record.sex: |
---|
| 141 | d['sex'] = 'female' |
---|
| 142 | if student_record.faculty in ('MED','DEN') and level > 400: |
---|
| 143 | bt += "_med" |
---|
| 144 | elif student_record.course in ekehuan_certificates: |
---|
| 145 | bt += "_ekenhuan" |
---|
| 146 | #elif student_record.course in pti_certificates: |
---|
| 147 | # bt += "_pti" |
---|
| 148 | info['sex']=d['sex'] |
---|
| 149 | d['bt'] = bt |
---|
| 150 | student_status = "%(sex)s_%(bt)s" % d |
---|
| 151 | info['student_status'] = student_status |
---|
| 152 | return info |
---|