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