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

Last change on this file since 1371 was 1206, checked in by joachim, 18 years ago

fix

  • Property svn:keywords set to Id
File size: 3.6 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 1206 2007-01-05 18:24:56Z joachim $
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    logger.info('"%s", "new bed allocation failed","%s"' % (student_id,code))
60    redirect("%s/%s/%s" % (students.absolute_url(),student,info['acco_id']))
61
62info = {}
63records = [r for r in beds() if  r.student]
64list = []
65to_modify = []
66for r in records:
67    info = context.getAccommodationInfo(r.student)
68    sbt = info.get('student_status',None)
69    if sbt is None:
70        continue
71    elif r.bed_type == sbt:
72        list.append("Student %s bed_type %s ok" % (r.student,r.bed_type))
73        continue
74    list.append("Student %s bed_type %s != %s" % (r.student,
75                                                  r.bed_type,
76                                                  info['student_status']))
77    to_modify.append((r.bed,r.student,info['student_status'],info['acco_doc']))
78for former_bed, student, status,acco_doc in to_modify:
79    beds.modifyRecord(bed=former_bed,student='')
80    code,bed = beds.searchAndReserveBed(student,status)
81    if code > 0:
82        #from Products.zdb import set_trace; set_trace()
83        d = {}
84        d['bed'] = bed
85        d['student_status'] = status
86        acco_info = context.waeup_tool.getAccommodationInfo(bed)
87        d['acco_maint_code'] = acco_info.get('maintenance_code')
88        d['acco_maint_fee'] = acco_info.get('maintenance_fee')
89        acco_doc.edit(mapping=d)
90        list.append("Student %s new bed %s assigned code = %s" % (student,
91                                                              bed,
92                                                              code))
93return "\r".join(list)
Note: See TracBrowser for help on using the repository browser.