source: WAeUP_SRP/trunk/skins/waeup_fceokene/getAccommodationInfo.py @ 11889

Last change on this file since 11889 was 5418, checked in by Henrik Bettermann, 14 years ago

Implement accommodation switch.

File size: 3.5 KB
Line 
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"""
12return Info about the current Student
13"""
14import logging
15logger = logging.getLogger('Skins.getAccommodationInfo')
16import DateTime
17
18pprops = context.portal_properties
19booking_disabled = not pprops.enable_acco_booking
20
21request = context.REQUEST
22mtool = context.portal_membership
23wf = context.portal_workflow
24member = mtool.getAuthenticatedMember()
25member_id = str(member)
26path_info = request.get('PATH_INFO').split('/')
27
28if mtool.isAnonymousUser():
29    return None
30info = {}
31if 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
40student_record = context.students_catalog.getRecordByKey(student_id)
41if student_record is None:
42    logger.info('%s not found in students_catalog' % student_id)
43    return None
44
45info['error'] = None
46info['matric_no']=student_record.matric_no
47info['jamb_reg_no']=student_record.jamb_reg_no
48info['name']=student_record.name
49info['email']=student_record.email
50info['level']=student_record.level
51info['verdict']=getattr(student_record,'verdict','')
52review_state = info['review_state'] = student_record.review_state
53info['session'] = session = context.getSessionId()
54students_object = context.portal_url.getPortalObject().campus.students
55student = getattr(students_object, student_id)
56info['student_id'] = student_id
57info['student'] = student
58
59# do not change these settings!
60
61booking_allowed = False
62info['booking_disabled'] = False
63
64# customize from here
65
66try:
67    level = int(student_record.level)
68except:
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
75try:
76    arrived = int(student_record.session) == int(session[0])
77except:
78    arrived = False
79    logger.info('%s has invalid session %s' % (student_id,student_record.session))
80
81if review_state in ('school_fee_paid','courses_registered', 'courses_validated',) and arrived:
82    info['booking_allowed'] = True
83    info['online_payment'] = True
84else:
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
91d = {}
92if level >= 300:
93   bt = 'fi'
94if level == 100:
95    bt = 'fr'
96elif level < 100:
97    bt = 'pr'   
98elif level < 300:
99    bt = 're'
100
101d['sex'] = 'male'
102if student_record.sex:
103    d['sex'] = 'female'
104
105
106info['sex']=d['sex']
107d['bt'] = bt
108student_status = "%(sex)s_%(bt)s" % d
109info['student_status'] = student_status
110
111# customize end
112
113acco_id = 'accommodation_' + session[0]
114acco = getattr(student,acco_id,None)
115info['acco'] = acco
116info['acco_id'] = acco_id
117info['maintenance_paid'] = False
118if 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"
122elif booking_disabled:
123    info['booking_disabled'] = True
124    logger.info('%s: %s eligible but booking disabled' % (student_id,student_status)) 
125
126return info
127
Note: See TracBrowser for help on using the repository browser.