source: WAeUP_SRP/trunk/skins/waeup_accommodation/cancel_allocation.py @ 6698

Last change on this file since 6698 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: 1.7 KB
Line 
1## Script (Python) "cancel_allocation"
2##bind container=container
3##bind context=context
4##bind namespace=
5##bind script=script
6##bind subpath=traverse_subpath
7##parameters=session=None
8##title=
9##
10# $Id: cancel_allocation.py 5616 2010-12-27 10:18:18Z henrik $
11"""
12cancel bed allocation (former release_bed)
13"""
14import logging
15logger = logging.getLogger('Skins.cancel_allocation')
16
17import DateTime
18current = DateTime.DateTime()
19request = context.REQUEST
20redirect = request.RESPONSE.redirect
21mtool = context.portal_membership
22wf = context.portal_workflow
23member = mtool.getAuthenticatedMember()
24member_id = str(member)
25path_info = request.get('PATH_INFO').split('/')
26students = context.portal_url.getPortalObject().campus.students
27student_id = context.getStudentId()
28
29if not context.isSectionOfficer():
30    logger.info('%s tried to access %s' % (member_id,student_id))
31    return None
32
33if student_id is not None:
34    logger.info('%s requests bed_release for %s' % (member_id,student_id))
35    res = context.portal_accommodation(student=student_id)
36    if len(res) == 0:
37        logger.info('no bed of %s found' % (student_id))
38        return redirect("%s/%s/accommodations" % (students.absolute_url(),student_id))
39    allocated_bed = res[0]
40    context.portal_accommodation.modifyRecord(bed=allocated_bed.bed,student=context.portal_accommodation.not_occupied)
41    data = {}
42    data['catkey'] = student_id + '|' + session
43    data['bed'] = "-- cancelled on %s by section officer --" % context.getDateStr(fmt='%d/%m/%Y', dt=current)
44    data['acco_maint_fee'] = ""
45    #set_trace()
46    context.accommodation_catalog.modifyRecord(**data)
47    logger.info('%s released bed of %s' % (member_id,student_id))
48    return redirect("%s/%s/accommodations" % (students.absolute_url(),student_id))
49
50return None
51
Note: See TracBrowser for help on using the repository browser.