source: WAeUP_SRP/base/skins/waeup_accommodation/change_bed.py @ 3151

Last change on this file since 3151 was 3151, checked in by Henrik Bettermann, 17 years ago

add psm

do not release bed if bed change fails

  • Property svn:keywords set to Id
File size: 4.4 KB
Line 
1## Script (Python) "change_bed"
2##bind container=container
3##bind context=context
4##bind namespace=
5##bind script=script
6##bind subpath=traverse_subpath
7##parameters=
8##title=
9##
10# $Id: change_bed.py 3151 2008-02-12 20:03:59Z henrik $
11"""
12relocate to a new bed if allocated bed is wrong
13"""
14import logging
15logger = logging.getLogger('Skins.change_bed')
16
17request = context.REQUEST
18redirect = request.RESPONSE.redirect
19mtool = context.portal_membership
20wf = context.portal_workflow
21member = mtool.getAuthenticatedMember()
22member_id = str(member)
23path_info = request.get('PATH_INFO').split('/')
24
25if mtool.isAnonymousUser():
26    return None
27students = context.portal_url.getPortalObject().campus.students
28beds = context.portal_accommodation
29studs = context.students_catalog
30student_id = context.getStudentId()
31
32if student_id is not None:
33    logger.info('%s requests bed change for %s' % (member_id,student_id))
34    info = context.getAccommodationInfo(student_id)
35    if info['acco'] is None:
36        logger.info('No accommodation object for %s' % (student_id))
37        return redirect("%s/%s/no_booking_allowed" % (students.absolute_url(),student_id))
38    res = beds(student=student_id)
39    status = info['student_status']
40    if len(res) == 0:
41        logger.info('No bed allocated for %s' % (student_id))
42        #return redirect("%s/%s" % (students.absolute_url(),student_id))
43    else:
44        allocated_bed = res[0]
45    code,bed = beds.searchAndReserveBed(student_id,status)
46    if code > 0:
47        if res:
48            if allocated_bed.bed_type == status:
49                logger.info('Status %s of %s has not changed' % (status,student_id))
50                psm='Student status has not changed!'
51                return redirect("%s/%s/%s/waeup_document_view?portal_status_message=%s" % (students.absolute_url(),student_id,info['acco_id'],psm))
52            logger.info('Bed status %s of %s has changed to %s' % (allocated_bed.bed_type,student_id,status))
53            beds.modifyRecord(bed=allocated_bed.bed,student=beds.not_occupied)
54            logger.info('Bed %s released' % (allocated_bed.bed))   
55        d = {}
56        d['bed'] = bed
57        d['student_status'] = status
58        acco_info = context.waeup_tool.getHallInfo(bed)
59        d['acco_maint_code'] = acco_info.get('maintenance_code')
60        d['acco_maint_fee'] = acco_info.get('maintenance_fee')
61        acco_doc = info['acco_doc']
62        acco_doc.edit(mapping=d)
63        logger.info('Bed %s allocated to %s' % (bed,student_id))
64        psm='Bed changed!'
65        return redirect("%s/%s/%s/waeup_document_view?portal_status_message=%s" % (students.absolute_url(),student_id,info['acco_id'],psm))
66    #acco_doc = info['acco_doc']
67    #acco_doc.edit(mapping={'bed':"-- cancelled by officer due to failed bed change request --"})
68    logger.info('New bed allocation for %s failed, code = %s' % (student_id,code))
69    #logger.info('%s cancelled booking of bed %s by %s' % (member,bed,student_id))
70    psm='Bed change failed!'
71    return redirect("%s/%s/%s/waeup_document_view?portal_status_message=%s" % (students.absolute_url(),student_id,info['acco_id'],psm))
72
73info = {}
74records = [r for r in beds() if  r.student]
75list = []
76to_modify = []
77for r in records:
78    info = context.getAccommodationInfo(r.student)
79    sbt = info.get('student_status',None)
80    if sbt is None:
81        continue
82    elif r.bed_type == sbt:
83        list.append("Student %s bed_type %s ok" % (r.student,r.bed_type))
84        continue
85    list.append("Student %s bed_type %s != %s" % (r.student,
86                                                  r.bed_type,
87                                                  info['student_status']))
88    to_modify.append((r.bed,r.student,info['student_status'],info['acco_doc']))
89for former_bed, student, status,acco_doc in to_modify:
90    beds.modifyRecord(bed=former_bed,student='')
91    code,bed = beds.searchAndReserveBed(student,status)
92    if code > 0:
93        #from Products.zdb import set_trace; set_trace()
94        d = {}
95        d['bed'] = bed
96        d['student_status'] = status
97        acco_info = context.waeup_tool.getHallInfo(bed)
98        d['acco_maint_code'] = acco_info.get('maintenance_code')
99        d['acco_maint_fee'] = acco_info.get('maintenance_fee')
100        acco_doc.edit(mapping=d)
101        list.append("New bed %s allocated to %s, code = %s" % (bed,
102                                                              student,
103                                                              code))
104return "\r".join(list)
Note: See TracBrowser for help on using the repository browser.