source: WAeUP_SRP/trunk/skins/waeup_fceokene/getAccommodationRecords.py @ 17952

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

Section Officer must be able to see the bed coordinates.

  • Property svn:keywords set to Id
File size: 2.6 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 5793 2011-03-03 14:01:26Z 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    # Okene special
59    if not (info['is_so'] or row['paid']):
60        row['bed'] = 'visible after payment'
61    row['current_unpaid'] = not row['paid'] and ar.session == portal_session
62    row['url'] = student_path
63    row['cancellation_allowed'] = info['is_so'] and ar.session == portal_session
64    row['relocation_allowed'] = info['is_so'] and ar.session == portal_session
65    accommodations.append(row)
66
67accommodations.sort(cmp=lambda x,y: cmp(x['sort_param'],y['sort_param']))
68
69info['accommodations'] = accommodations
70
71as = context.getAccommodationStatus()
72info['booking_allowed'] = as['booking_allowed']
73info['booking_disabled'] = as['booking_disabled']
74
75return info
76                 
77   
78   
Note: See TracBrowser for help on using the repository browser.