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