source: WAeUP_SRP/trunk/skins/waeup_accommodation/getAccommodationRecords.py @ 17929

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

Implementation of a Late Registration Fee (FUTMinna only). This was more work and customization than expected. We urgently need a new consistent payment module.

  • Property svn:keywords set to Id
File size: 2.9 KB
Line 
1## Script (Python) "getAccommodationRecords"
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: getAccommodationRecords.py 5795 2011-03-05 12:34:09Z henrik $
11"""
12"""
13import logging
14logger = logging.getLogger('Skins.getAccommodationRecords')
15import DateTime
16
17pprops = context.portal_properties
18booking_disabled = not pprops.enable_acco_booking
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('/')
26portal_session = context.getSessionId()[0]
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['is_so'] = context.isSectionOfficer()
46info['is_student'] = context.isStudent()
47info['student_name'] = student_record.name   
48student_path = "%s/campus/students/%s" % (context.portal_url(),student_id)
49accommodation_records = context.accommodation_catalog(student_id = student_id)
50accommodations = []
51for ar in accommodation_records:
52    row = {}
53    row['sort_param'] = ar.session[-2:]  # in 2006 we used the session attribute was 2006 and not 06
54    row['session'] = ar.session
55    row['bed'] = ar.bed
56    row['reservation_status'] = ar.reservation_status
57    row['paid'] = ar.reservation_status == 'maintenance_fee_paid'
58    row['current_unpaid'] = not row['paid'] and ar.session == portal_session and \
59                                                student_record.review_state in ('cleared_and_validated',
60                                                                                'school_fee_paid',
61                                                                                'courses_registered',
62                                                                                'courses_validated',)
63    row['url'] = student_path
64    row['cancellation_allowed'] = info['is_so'] and ar.session == portal_session
65    row['relocation_allowed'] = info['is_so'] and ar.session == portal_session
66    accommodations.append(row)
67
68accommodations.sort(cmp=lambda x,y: cmp(x['sort_param'],y['sort_param']))
69
70info['accommodations'] = accommodations
71
72as = context.getAccommodationStatus()
73info['booking_allowed'] = as['booking_allowed']
74info['booking_disabled'] = as['booking_disabled']
75
76return info
77                 
78   
79   
Note: See TracBrowser for help on using the repository browser.