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 | |
---|
19 | pprops = context.portal_properties |
---|
20 | booking_disabled = not pprops.enable_acco_booking |
---|
21 | |
---|
22 | |
---|
23 | request = context.REQUEST |
---|
24 | mtool = context.portal_membership |
---|
25 | wf = context.portal_workflow |
---|
26 | member = mtool.getAuthenticatedMember() |
---|
27 | member_id = str(member) |
---|
28 | path_info = request.get('PATH_INFO').split('/') |
---|
29 | |
---|
30 | if mtool.isAnonymousUser(): |
---|
31 | return None |
---|
32 | info = {} |
---|
33 | if student_id is None: |
---|
34 | requested_id = context.getStudentId() |
---|
35 | if requested_id and not context.isStaff() and member_id != requested_id: |
---|
36 | logger.info('%s tried to access %s' % (member_id,requested_id)) |
---|
37 | return None |
---|
38 | elif context.isStaff(): |
---|
39 | student_id = requested_id |
---|
40 | else: |
---|
41 | student_id = member_id |
---|
42 | student_record = context.students_catalog.getRecordByKey(student_id) |
---|
43 | if student_record is None: |
---|
44 | logger.info('%s not found in students_catalog' % student_id) |
---|
45 | return None |
---|
46 | |
---|
47 | info['error'] = None |
---|
48 | info['matric_no']=student_record.matric_no |
---|
49 | info['jamb_reg_no']=student_record.jamb_reg_no |
---|
50 | info['name']=student_record.name |
---|
51 | info['email']=student_record.email |
---|
52 | info['level']=student_record.level |
---|
53 | info['verdict']=getattr(student_record,'verdict','') |
---|
54 | review_state = info['review_state'] = student_record.review_state |
---|
55 | info['session'] = session = context.getSessionId() |
---|
56 | students_object = context.portal_url.getPortalObject().campus.students |
---|
57 | student = getattr(students_object, student_id) |
---|
58 | info['student_id'] = student_id |
---|
59 | info['student'] = student |
---|
60 | |
---|
61 | # do not change these settings! |
---|
62 | |
---|
63 | booking_allowed = False |
---|
64 | info['booking_disabled'] = False |
---|
65 | |
---|
66 | # customize from here |
---|
67 | |
---|
68 | try: |
---|
69 | level = int(student_record.level) |
---|
70 | except: |
---|
71 | logger.info('%s has invalid level %s' % (student_id,student_record.level)) |
---|
72 | info['acco'] = None |
---|
73 | info['booking_allowed'] = False |
---|
74 | info['student_status'] = '' |
---|
75 | return info |
---|
76 | |
---|
77 | if review_state in ('cleared_and_validated','school_fee_paid','courses_registered', 'courses_validated',) and student_record.session == session[0]: |
---|
78 | info['booking_allowed'] = True |
---|
79 | info['online_payment'] = True |
---|
80 | # returning student can also book without having paid the school fee (see ticket #29) |
---|
81 | #elif review_state == 'returning' and int(student_record.session)+1 == int(session[0]): |
---|
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'] = '' |
---|
88 | logger.info('%s: not eligible' % (student_id)) |
---|
89 | return info |
---|
90 | |
---|
91 | d = {} |
---|
92 | d['sex'] = 'male' |
---|
93 | #d['bt'] = 'all' |
---|
94 | if student_record.sex: |
---|
95 | d['sex'] = 'female' |
---|
96 | |
---|
97 | if level == 100: |
---|
98 | d['bt'] = 'fr' |
---|
99 | else: |
---|
100 | d['bt'] = 're' |
---|
101 | |
---|
102 | info['sex']=d['sex'] |
---|
103 | student_status = "%(sex)s_%(bt)s" % d |
---|
104 | info['student_status'] = student_status |
---|
105 | |
---|
106 | # customize end |
---|
107 | |
---|
108 | acco_id = 'accommodation_' + session[0] |
---|
109 | acco = getattr(student,acco_id,None) |
---|
110 | info['acco'] = acco |
---|
111 | info['acco_id'] = acco_id |
---|
112 | info['maintenance_paid'] = False |
---|
113 | if acco is not None: |
---|
114 | info['acco_doc'] = acco.getContent() |
---|
115 | info['acco_review_state'] = wf.getInfoFor(acco,'review_state',None) |
---|
116 | info['maintenance_paid'] = info['acco_review_state'] == "maintenance_fee_paid" |
---|
117 | elif booking_disabled: |
---|
118 | info['booking_disabled'] = True |
---|
119 | logger.info('%s: %s eligible but booking disabled' % (student_id,student_status)) |
---|
120 | |
---|
121 | return info |
---|