source: WAeUP_SRP/trunk/skins/waeup_accommodation/change_bed.py @ 1468

Last change on this file since 1468 was 1452, checked in by Henrik Bettermann, 18 years ago
  • Property svn:keywords set to Id
File size: 4.0 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 1452 2007-02-20 22:23:22Z henrik $
11"""
12relocate to a new bed if allocated bed is wrong
13"""
14import logging
15logger = logging.getLogger('Student.Accommodation.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    res = beds(student=student_id)
36    if len(res) == 0:
37        logger.info('"%s", "no bed found"' % (student_id))
38        redirect("%s/%s" % (students.absolute_url(),student_id))
39    allocated_bed = res[0]
40    status = info['student_status']
41    student = student_id
42    if allocated_bed.bed_type == status:
43        logger.info('"%s", "correct bed allocated","%s"' % (student_id,status))
44        redirect("%s/%s/%s" % (students.absolute_url(),student,info['acco_id']))
45    logger.info('"%s", "change bed", "%s/%s"' % (student_id,allocated_bed.bed_type,status))
46    beds.modifyRecord(bed=allocated_bed.bed,student='')
47    code,bed = beds.searchAndReserveBed(student_id,status)
48    if code > 0:
49        #from Products.zdb import set_trace; set_trace()
50        d = {}
51        d['bed'] = bed
52        d['student_status'] = status
53        acco_info = context.waeup_tool.getAccommodationInfo(bed)
54        d['acco_maint_code'] = acco_info.get('maintenance_code')
55        d['acco_maint_fee'] = acco_info.get('maintenance_fee')
56        acco_doc = info['acco_doc']
57        acco_doc.edit(mapping=d)
58        return redirect("%s/%s/%s" % (students.absolute_url(),student,info['acco_id']))
59    student_obj = getattr(students,student_id)
60    acco_id = "accommodation_%s" % context.getSessionId()
61    if acco_id in student_obj.objectIds():
62        acco_doc = getattr(student_obj, acco_id).getContent()
63        if acco_doc.bed == bed:
64            acco_doc.edit(mapping={'bed':"-- cancelled by %s --" % member})
65    logger.info('"%s", "new bed allocation failed","%s"' % (student_id,code))
66    logger.info('"%s","cancelled booking of bed %s by %s"' % (member,bed,sid))
67    redirect("%s/%s/%s" % (students.absolute_url(),student,info['acco_id']))
68
69info = {}
70records = [r for r in beds() if  r.student]
71list = []
72to_modify = []
73for r in records:
74    info = context.getAccommodationInfo(r.student)
75    sbt = info.get('student_status',None)
76    if sbt is None:
77        continue
78    elif r.bed_type == sbt:
79        list.append("Student %s bed_type %s ok" % (r.student,r.bed_type))
80        continue
81    list.append("Student %s bed_type %s != %s" % (r.student,
82                                                  r.bed_type,
83                                                  info['student_status']))
84    to_modify.append((r.bed,r.student,info['student_status'],info['acco_doc']))
85for former_bed, student, status,acco_doc in to_modify:
86    beds.modifyRecord(bed=former_bed,student='')
87    code,bed = beds.searchAndReserveBed(student,status)
88    if code > 0:
89        #from Products.zdb import set_trace; set_trace()
90        d = {}
91        d['bed'] = bed
92        d['student_status'] = status
93        acco_info = context.waeup_tool.getAccommodationInfo(bed)
94        d['acco_maint_code'] = acco_info.get('maintenance_code')
95        d['acco_maint_fee'] = acco_info.get('maintenance_fee')
96        acco_doc.edit(mapping=d)
97        list.append("Student %s new bed %s assigned code = %s" % (student,
98                                                              bed,
99                                                              code))
100return "\r".join(list)
Note: See TracBrowser for help on using the repository browser.