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

Last change on this file since 3905 was 3863, checked in by Henrik Bettermann, 16 years ago

getPaymentsFolderInfo.py: resolve #600
getAccommodationInfo.py: implement disable switch
WAeUPImport.py: export student password

File size: 4.2 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
18booking_disabled = False
19
20request = context.REQUEST
21mtool = context.portal_membership
22wf = context.portal_workflow
23member = mtool.getAuthenticatedMember()
24member_id = str(member)
25path_info = request.get('PATH_INFO').split('/')
26
27if mtool.isAnonymousUser():
28    return None
29info = {}
30if 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
39student_record = context.students_catalog.getRecordByKey(student_id)
40if student_record is None:
41    logger.info('%s not found in students_catalog' % student_id)
42    return None
43
44info['error'] = None
45info['matric_no']=student_record.matric_no
46info['jamb_reg_no']=student_record.jamb_reg_no
47info['name']=student_record.name
48info['email']=student_record.email
49info['level']=student_record.level
50info['verdict']=getattr(student_record,'verdict','')
51review_state = info['review_state'] = student_record.review_state
52info['session'] = session = context.getSessionId()
53students_object = context.portal_url.getPortalObject().campus.students
54student = getattr(students_object, student_id)
55info['student_id'] = student_id
56info['student'] = student
57
58booking_allowed = False
59
60# customize from here
61
62ekehuan_certificates = ('BARTAPG',
63                        'BARTAPM',
64                        'BARTCER',
65                        'BARTFAA',
66                        'BARTFAP',
67                        'BARTSCP',
68                        'BARTTXT',
69                        'BARTMAS',
70                        'BARTTHR',
71                        )
72
73new_states = ('cleared_and_validated',
74              'school_fee_paid',
75              'courses_registered',
76              'courses_validated',
77              )
78
79new = student_record.entry_session == session[0]
80arrived = student_record.session == session[0]
81
82level = None
83end_level = None
84previous = None
85
86try:
87    level = int(student_record.level)
88except:
89    logger.info('%s has invalid level %s' % (student_id,student_record.level))
90try:
91    end_level = int(student_record.end_level)
92except:
93    logger.info('%s has invalid end_level %s' % (student_id,student_record.end_level))
94try:
95    previous = int(student_record.session) == int(session[0]) - 1
96except:
97    logger.info('%s has invalid session %s' % (student_id,student_record.session))
98
99if level is None or end_level is None or student_record.review_state == 'deactivated':
100    pass
101elif arrived:
102    if new:
103        booking_allowed = student_record.review_state in new_states
104    else:
105        booking_allowed = not (level % 100)
106elif previous:
107    booking_allowed = student_record.verdict in ('A','B',)
108
109info['booking_allowed'] = booking_allowed
110if not booking_allowed:
111    info['acco'] = None
112    info['student_status'] = ''
113    return info
114
115acco_id = 'accommodation_' + session[0]
116acco = getattr(student,acco_id,None)
117info['acco'] = acco
118info['acco_id'] = acco_id
119bt = 're'
120info['maintenance_paid'] = False
121if acco is not None:
122    info['acco_doc'] = acco.getContent()
123    info['acco_review_state'] = wf.getInfoFor(acco,'review_state',None)
124    info['maintenance_paid'] = info['acco_review_state'] == "maintenance_fee_paid"
125elif booking_disabled:
126    info['booking_allowed'] = False
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'
138
139d['sex'] = 'male'
140if student_record.sex:
141    d['sex'] = 'female'
142if student_record.faculty in ('MED','DEN') and level > 400:
143    bt += "_med"
144elif student_record.course in ekehuan_certificates:
145    bt += "_ekenhuan"
146#elif student_record.course in pti_certificates:
147#    bt += "_pti"
148info['sex']=d['sex']
149d['bt'] = bt
150student_status = "%(sex)s_%(bt)s" % d
151info['student_status'] = student_status
152return info
Note: See TracBrowser for help on using the repository browser.