source: WAeUP_SRP/trunk/skins/waeup_accommodation/getAccommodationStatus.py @ 15398

Last change on this file since 15398 was 7131, checked in by Henrik Bettermann, 13 years ago

Students couldn't be relocated after changing the sex attribute because the value was taken from the existing accommodation record.

  • Property svn:keywords set to Id
File size: 5.3 KB
Line 
1## Script (Python) "getAccommodationStatus"
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: getAccommodationStatus.py 7131 2011-11-17 16:38:45Z henrik $
11"""
12return Info about the current Student
13"""
14try:
15    from Products.zdb import set_trace
16except:
17    def set_trace():
18        pass
19
20import logging
21logger = logging.getLogger('Skins.getAccommodationStatus')
22import DateTime
23
24pprops = context.portal_properties
25booking_disabled = not pprops.enable_acco_booking
26
27request = context.REQUEST
28mtool = context.portal_membership
29wf = context.portal_workflow
30member = mtool.getAuthenticatedMember()
31member_id = str(member)
32path_info = request.get('PATH_INFO').split('/')
33
34if mtool.isAnonymousUser():
35    return None
36info = {}
37if student_id is None:
38    requested_id = context.getStudentId()
39    if requested_id and not context.isStaff() and member_id != requested_id:
40        logger.info('%s tried to access %s' % (member_id,requested_id))
41        return None
42    elif context.isStaff():
43        student_id = requested_id
44    else:
45        student_id = member_id
46student_record = context.students_catalog.getRecordByKey(student_id)
47if student_record is None:
48    logger.info('%s not found in students_catalog' % student_id)
49    return None
50
51info['error'] = None
52info['matric_no']=student_record.matric_no
53info['jamb_reg_no']=student_record.jamb_reg_no
54info['name']=student_record.name
55info['email']=student_record.email
56info['level']=student_record.level
57info['verdict']=getattr(student_record,'verdict','')
58review_state = info['review_state'] = student_record.review_state
59info['session'] = session = context.getSessionId()
60students_object = context.portal_url.getPortalObject().campus.students
61student = getattr(students_object, student_id)
62info['student_id'] = student_id
63info['student'] = student
64
65# do not change these settings!
66
67booking_allowed = False
68info['booking_disabled'] = False
69
70# customize from here
71
72ekehuan_certificates = ('BARTAPG',
73                        'BARTAPM',
74                        'BARTCER',
75                        'BARTFAA',
76                        'BARTFAP',
77                        'BARTSCP',
78                        'BARTTXT',
79                        'BARTMAS',
80                        'BARTTHR',
81                        )
82
83new_states = ('cleared_and_validated',
84              'school_fee_paid',
85              'courses_registered',
86              'courses_validated',
87              )
88new = None
89arrived = None
90
91try:
92    new = int(student_record.entry_session) == int(session[0])
93except:   
94    logger.info('%s has invalid entry_session %s' % (student_id,student_record.entry_session))
95try:
96    arrived = int(student_record.session) == int(session[0])
97except:   
98    logger.info('%s has invalid session %s' % (student_id,student_record.session))   
99   
100level = None
101end_level = None
102previous = None
103
104try:
105    level = int(student_record.level)
106except:
107    logger.info('%s has invalid level %s' % (student_id,student_record.level))
108try:
109    end_level = int(student_record.end_level)
110except:
111    logger.info('%s has invalid end_level %s' % (student_id,student_record.end_level))
112try:
113    previous = int(student_record.session) == int(session[0]) - 1
114except:
115    logger.info('%s has invalid session %s' % (student_id,student_record.session))
116
117if level is None or end_level is None or student_record.review_state in ('deactivated','graduated'):
118    pass
119elif arrived:
120    if new:
121        booking_allowed = student_record.review_state in new_states
122    else:
123        booking_allowed = not (level % 100)
124elif previous:
125    booking_allowed = student_record.verdict in ('A','B',)
126
127info['booking_allowed'] = booking_allowed
128if not booking_allowed:
129    info['student_status'] = ''
130    #info['new'] = new
131    #logger.info('%s: not eligible' % (student_id))     
132    return info
133
134d = {}
135delta = 0
136if previous:
137    delta = 100
138if new:
139    bt = 'fr'
140elif level + delta < end_level:
141    bt = 're'
142else:
143    bt = 'fi'
144d['sex'] = 'male'
145if student_record.sex:
146    d['sex'] = 'female'
147if student_record.faculty in ('MED','DEN') and level > 400:
148    bt += "_med"
149elif student_record.course in ekehuan_certificates:
150    bt += "_ekenhuan"
151#elif student_record.course in pti_certificates:
152#    bt += "_pti"
153info['sex']=d['sex']
154d['bt'] = bt
155student_status = "%(sex)s_%(bt)s" % d
156info['student_status'] = student_status
157
158# customize end
159
160acco_id = student_id + '|' + session[0]
161info['acco_id'] = acco_id
162
163if booking_disabled:
164  info['booking_disabled'] = True
165  #logger.info('%s: %s eligible but booking disabled' % (student_id,student_status)) 
166
167accommodation_record = context.accommodation_catalog.getRecordByKey(acco_id)
168if accommodation_record is None:
169    return info
170 
171info['booking_allowed'] = False
172info['acco_res_date'] = accommodation_record.acco_res_date
173info['acco_res_sc_pin'] = accommodation_record.acco_res_sc_pin
174info['acco_maint_fee'] = accommodation_record.acco_maint_fee
175info['acco_maint_code'] = accommodation_record.acco_maint_code
176info['bed'] = accommodation_record.bed
177info['session'] = accommodation_record.session
178info['maintenance_paid'] = accommodation_record.reservation_status == 'maintenance_fee_paid'
179
180return info
Note: See TracBrowser for help on using the repository browser.