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

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

getAccommodationInfo.py: deactivate histel booking fro graduates
srp_anonymous_view.pt: Use portal title for headline
portlet_student_workflow_display.pt: show state graduated

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