[5616] | 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 | """ |
---|
| 12 | cancel bed allocation (former release_bed) |
---|
| 13 | """ |
---|
| 14 | import logging |
---|
| 15 | logger = logging.getLogger('Skins.cancel_allocation') |
---|
| 16 | |
---|
| 17 | import DateTime |
---|
| 18 | current = DateTime.DateTime() |
---|
| 19 | request = context.REQUEST |
---|
| 20 | redirect = request.RESPONSE.redirect |
---|
| 21 | mtool = context.portal_membership |
---|
| 22 | wf = context.portal_workflow |
---|
| 23 | member = mtool.getAuthenticatedMember() |
---|
| 24 | member_id = str(member) |
---|
| 25 | path_info = request.get('PATH_INFO').split('/') |
---|
| 26 | students = context.portal_url.getPortalObject().campus.students |
---|
| 27 | student_id = context.getStudentId() |
---|
| 28 | |
---|
| 29 | if not context.isSectionOfficer(): |
---|
| 30 | logger.info('%s tried to access %s' % (member_id,student_id)) |
---|
| 31 | return None |
---|
| 32 | |
---|
| 33 | if 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 | |
---|
| 50 | return None |
---|
| 51 | |
---|