source: WAeUP_SRP/trunk/skins/waeup_accommodation/relocate.py @ 9089

Last change on this file since 9089 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: 3.3 KB
Line 
1## Script (Python) "relocate"
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: relocate.py 5616 2010-12-27 10:18:18Z henrik $
11"""
12relocate to a new bed if allocated bed is wrong (former change_bed)
13"""
14import logging
15from Products.AdvancedQuery import Eq, Between, Le,In
16
17logger = logging.getLogger('Skins.relocate')
18request = context.REQUEST
19redirect = request.RESPONSE.redirect
20mtool = context.portal_membership
21wf = context.portal_workflow
22member = mtool.getAuthenticatedMember()
23member_id = str(member)
24path_info = request.get('PATH_INFO').split('/')
25students = context.portal_url.getPortalObject().campus.students
26portal_acco_cat = context.portal_accommodation
27studs = context.students_catalog
28student_id = context.getStudentId()
29
30if not context.isSectionOfficer():
31    logger.info('%s tried to access %s' % (member_id,student_id))
32    return None
33
34if student_id is not None:
35    logger.info('%s requests bed change for %s' % (member_id,student_id))
36    info = context.getAccommodationStatus(student_id)
37    res = portal_acco_cat(student=student_id)
38    status = info['student_status']
39    while True:
40        if len(res) == 0:
41            psm = 'No bed allocated for %s' % (student_id)
42            logger.info(psm)
43            pass
44            #break
45        elif res[0].bed_type.endswith("reserved"):
46             logger.info("found reserved bed %s which won't be released" % res[0].bed)
47             pass
48        else:
49            allocated_bed = res[0]
50            #if allocated_bed.bed_type == status:
51            #    logger.info('Status %s of %s has not changed.' % (status,student_id))
52            #    psm='Student status has not changed!'
53            #    break
54            logger.info('Bed status %s of %s has changed to %s.' % (allocated_bed.bed_type,student_id,status))
55            query = Eq('bed_type',status) & Eq('student',context.portal_accommodation.not_occupied)
56            records = context.portal_accommodation.evalAdvancedQuery(query)
57            if len(records) < 1:
58                psm='Bed change for %s failed, no free bed in category %s.' % (student_id,status)
59                logger.info(psm)
60                break
61            portal_acco_cat.modifyRecord(bed=allocated_bed.bed,student=portal_acco_cat.not_occupied)
62            logger.info('Bed %s released' % (allocated_bed.bed))
63        code,bed = portal_acco_cat.searchAndReserveBed(student_id,status,random_order=True)
64        if code > -2:
65            acco_info = context.waeup_tool.getHallInfo(bed)
66            d = {}
67            d['bed'] = bed
68            d['student_status'] = status
69            d['catkey'] = student_id + '|' + session
70            d['acco_maint_code'] = acco_info.get('maintenance_code')
71            d['acco_maint_fee'] = acco_info.get('maintenance_fee')
72            context.accommodation_catalog.modifyRecord(**d)
73        if code > 0:
74            psm = 'Bed changed!'
75            logger.info('Bed %s allocated to %s' % (bed,student_id))
76        elif code == -1:
77            psm = 'A reserved bed has been allocated.'
78        elif code == -2:
79            psm = 'No bed %s for %s available!' % (status,student_id)
80        else:
81            psm = 'Bed change failed!'
82        break
83
84return redirect("%s/%s/accommodations" % (students.absolute_url(),student_id))
85
86
Note: See TracBrowser for help on using the repository browser.