source: WAeUP_SRP/trunk/skins/waeup_accommodation/getAccommodationInfo.py @ 8384

Last change on this file since 8384 was 5224, checked in by Henrik Bettermann, 15 years ago

disable unnecessary logging

File size: 4.8 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
66ekehuan_certificates = ('BARTAPG',
67                        'BARTAPM',
68                        'BARTCER',
69                        'BARTFAA',
70                        'BARTFAP',
71                        'BARTSCP',
72                        'BARTTXT',
73                        'BARTMAS',
74                        'BARTTHR',
75                        )
76
77new_states = ('cleared_and_validated',
78              'school_fee_paid',
79              'courses_registered',
80              'courses_validated',
81              )
82new = None
83arrived = None
84
85try:
86    new = int(student_record.entry_session) == int(session[0])
87except:   
88    logger.info('%s has invalid entry_session %s' % (student_id,student_record.entry_session))
89try:
90    arrived = int(student_record.session) == int(session[0])
91except:   
92    logger.info('%s has invalid session %s' % (student_id,student_record.session))   
93   
94level = None
95end_level = None
96previous = None
97
98try:
99    level = int(student_record.level)
100except:
101    logger.info('%s has invalid level %s' % (student_id,student_record.level))
102try:
103    end_level = int(student_record.end_level)
104except:
105    logger.info('%s has invalid end_level %s' % (student_id,student_record.end_level))
106try:
107    previous = int(student_record.session) == int(session[0]) - 1
108except:
109    logger.info('%s has invalid session %s' % (student_id,student_record.session))
110
111if level is None or end_level is None or student_record.review_state in ('deactivated','graduated'):
112    pass
113elif arrived:
114    if new:
115        booking_allowed = student_record.review_state in new_states
116    else:
117        booking_allowed = not (level % 100)
118elif previous:
119    booking_allowed = student_record.verdict in ('A','B',)
120
121info['booking_allowed'] = booking_allowed
122if not booking_allowed:
123    info['acco'] = None
124    info['student_status'] = ''
125    logger.info('%s: not eligible' % (student_id))     
126    return info
127
128d = {}
129delta = 0
130if previous:
131    delta = 100
132if new:
133    bt = 'fr'
134elif level + delta < end_level:
135    bt = 're'
136else:
137    bt = 'fi'
138d['sex'] = 'male'
139if student_record.sex:
140    d['sex'] = 'female'
141if student_record.faculty in ('MED','DEN') and level > 400:
142    bt += "_med"
143elif student_record.course in ekehuan_certificates:
144    bt += "_ekenhuan"
145#elif student_record.course in pti_certificates:
146#    bt += "_pti"
147info['sex']=d['sex']
148d['bt'] = bt
149student_status = "%(sex)s_%(bt)s" % d
150info['student_status'] = student_status
151
152# customize end
153
154acco_id = 'accommodation_' + session[0]
155acco = getattr(student,acco_id,None)
156info['acco'] = acco
157info['acco_id'] = acco_id
158info['maintenance_paid'] = False
159if acco is not None:
160    info['acco_doc'] = acco.getContent()
161    info['acco_review_state'] = wf.getInfoFor(acco,'review_state',None)
162    info['maintenance_paid'] = info['acco_review_state'] == "maintenance_fee_paid"
163elif booking_disabled:
164    info['booking_disabled'] = True
165    #logger.info('%s: %s eligible but booking disabled' % (student_id,student_status)) 
166
167return info
Note: See TracBrowser for help on using the repository browser.