[3690] | 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 | |
---|
[5418] | 18 | pprops = context.portal_properties |
---|
| 19 | booking_disabled = not pprops.enable_acco_booking |
---|
[4009] | 20 | |
---|
[3690] | 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 | |
---|
[4009] | 59 | # do not change these settings! |
---|
| 60 | |
---|
[3690] | 61 | booking_allowed = False |
---|
[4009] | 62 | info['booking_disabled'] = False |
---|
[3690] | 63 | |
---|
| 64 | # customize from here |
---|
| 65 | |
---|
| 66 | try: |
---|
| 67 | level = int(student_record.level) |
---|
| 68 | except: |
---|
| 69 | logger.info('%s has invalid level %s' % (student_id,student_record.level)) |
---|
| 70 | info['acco'] = None |
---|
| 71 | info['booking_allowed'] = False |
---|
| 72 | info['student_status'] = '' |
---|
| 73 | return info |
---|
| 74 | |
---|
[3960] | 75 | try: |
---|
| 76 | arrived = int(student_record.session) == int(session[0]) |
---|
| 77 | except: |
---|
| 78 | arrived = False |
---|
| 79 | logger.info('%s has invalid session %s' % (student_id,student_record.session)) |
---|
| 80 | |
---|
| 81 | if review_state in ('school_fee_paid','courses_registered', 'courses_validated',) and arrived: |
---|
[3690] | 82 | info['booking_allowed'] = True |
---|
| 83 | info['online_payment'] = True |
---|
| 84 | else: |
---|
| 85 | info['acco'] = None |
---|
| 86 | info['booking_allowed'] = False |
---|
| 87 | info['student_status'] = '' |
---|
[4009] | 88 | logger.info('%s: not eligible' % (student_id)) |
---|
[3690] | 89 | return info |
---|
| 90 | |
---|
| 91 | d = {} |
---|
| 92 | if level >= 300: |
---|
| 93 | bt = 'fi' |
---|
| 94 | if level == 100: |
---|
| 95 | bt = 'fr' |
---|
| 96 | elif level < 100: |
---|
| 97 | bt = 'pr' |
---|
| 98 | elif level < 300: |
---|
| 99 | bt = 're' |
---|
| 100 | |
---|
| 101 | d['sex'] = 'male' |
---|
| 102 | if student_record.sex: |
---|
| 103 | d['sex'] = 'female' |
---|
| 104 | |
---|
| 105 | |
---|
| 106 | info['sex']=d['sex'] |
---|
| 107 | d['bt'] = bt |
---|
| 108 | student_status = "%(sex)s_%(bt)s" % d |
---|
| 109 | info['student_status'] = student_status |
---|
[4009] | 110 | |
---|
| 111 | # customize end |
---|
| 112 | |
---|
| 113 | acco_id = 'accommodation_' + session[0] |
---|
| 114 | acco = getattr(student,acco_id,None) |
---|
| 115 | info['acco'] = acco |
---|
| 116 | info['acco_id'] = acco_id |
---|
| 117 | info['maintenance_paid'] = False |
---|
| 118 | if acco is not None: |
---|
| 119 | info['acco_doc'] = acco.getContent() |
---|
| 120 | info['acco_review_state'] = wf.getInfoFor(acco,'review_state',None) |
---|
| 121 | info['maintenance_paid'] = info['acco_review_state'] == "maintenance_fee_paid" |
---|
| 122 | elif booking_disabled: |
---|
| 123 | info['booking_disabled'] = True |
---|
| 124 | logger.info('%s: %s eligible but booking disabled' % (student_id,student_status)) |
---|
| 125 | |
---|
[3690] | 126 | return info |
---|
| 127 | |
---|