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

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

Further improvements for new accommodation booking.

  • Property svn:keywords set to Id
File size: 2.4 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 5621 2010-12-28 08:53:23Z 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
59    row['url'] = student_path
60    row['cancellation_allowed'] = info['is_so'] and ar.session == portal_session
61    row['relocation_allowed'] = info['is_so'] and ar.session == portal_session
62    accommodations.append(row)
63
64accommodations.sort(cmp=lambda x,y: cmp(x['sort_param'],y['sort_param']))
65
66info['accommodations'] = accommodations
67
68as = context.getAccommodationStatus()
69info['booking_allowed'] = as['booking_allowed']
70info['booking_disabled'] = as['booking_disabled']
71
72return info
73                 
74   
75   
Note: See TracBrowser for help on using the repository browser.