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 | #Excluding 400L students from hostel allocations |
---|
77 | if level not in (400,410,420,) and 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 | bt = 'fr' |
---|
99 | else: |
---|
100 | bt = 're' |
---|
101 | if student_record.faculty in ('SSE'): |
---|
102 | bt += "_sse" |
---|
103 | d['bt'] = bt |
---|
104 | |
---|
105 | info['sex']=d['sex'] |
---|
106 | student_status = "%(sex)s_%(bt)s" % d |
---|
107 | info['student_status'] = student_status |
---|
108 | |
---|
109 | # customize end |
---|
110 | |
---|
111 | acco_id = 'accommodation_' + session[0] |
---|
112 | acco = getattr(student,acco_id,None) |
---|
113 | info['acco'] = acco |
---|
114 | info['acco_id'] = acco_id |
---|
115 | info['maintenance_paid'] = False |
---|
116 | if acco is not None: |
---|
117 | info['acco_doc'] = acco.getContent() |
---|
118 | info['acco_review_state'] = wf.getInfoFor(acco,'review_state',None) |
---|
119 | info['maintenance_paid'] = info['acco_review_state'] == "maintenance_fee_paid" |
---|
120 | elif booking_disabled: |
---|
121 | info['booking_disabled'] = True |
---|
122 | logger.info('%s: %s eligible but booking disabled' % (student_id,student_status)) |
---|
123 | |
---|
124 | return info |
---|