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

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

Implement second part of new accommodation allocation module. This part contains the new scripts and page templates needed. See ReadMe?.txt for further instructions.

  • Property svn:keywords set to Id
File size: 2.2 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 5616 2010-12-27 10:18:18Z 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['session'] = ar.session
54    row['bed'] = ar.bed
55    row['reservation_status'] = ar.reservation_status
56    row['paid'] = ar.reservation_status == 'maintenance_fee_paid'
57    row['url'] = student_path
58    row['cancellation_allowed'] = info['is_so'] and ar.session == portal_session
59    row['relocation_allowed'] = info['is_so'] and ar.session == portal_session
60    accommodations.append(row)
61
62info['accommodations'] = accommodations
63
64as = context.getAccommodationStatus()
65info['booking_allowed'] = as['booking_allowed']
66info['booking_disabled'] = as['booking_disabled']
67
68return info
69                 
70   
71   
Note: See TracBrowser for help on using the repository browser.