source: WAeUP_SRP/trunk/skins/waeup_accommodation/book_reserved_bed.py @ 1444

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

added release reserved bed function.

  • Property svn:keywords set to Id
File size: 4.8 KB
Line 
1##parameters=REQUEST
2# $Id: book_reserved_bed.py 1444 2007-02-19 17:16:34Z joachim $
3"""
4process the the accommodation reservation
5"""
6import DateTime
7current = DateTime.DateTime()
8pr = context.portal_registration
9wftool = context.portal_workflow
10lt = context.portal_layouts
11mtool = context.portal_membership
12member = mtool.getAuthenticatedMember()
13acco_cat = context.portal_accommodation
14import logging
15logger = logging.getLogger('Accommodation.BookReservedBed')
16
17change = REQUEST.has_key("reserve_and_change")
18release = REQUEST.has_key("release")
19reserve = REQUEST.has_key("reserve")
20validate = release or change or (reserve and
21           REQUEST.get("reserve").startswith('Reserve'))
22mode = 'create'
23d = {}
24rendered,psm,ds = lt.renderLayout(layout_id= 'acco_bed_booking',
25                      schema_id= 'acco_bed_booking',
26                      context=context,
27                      mapping=validate and REQUEST,
28                      ob=d,
29                      layout_mode='edit',
30                      commit = False
31                      )
32if psm == 'invalid':
33    psm = "Please correct your input."
34    return context.book_reserved_bed_form(rendered = rendered,
35                                 psm = psm,
36                                 #psm = "%s, %s" % (psm,ds),
37                                 mode = mode,
38                                 formaction = "book_reserved_bed",
39                                 button = "Reserve Bed",
40                                 ds = ds,
41                                 )
42elif psm == '':
43    return context.book_reserved_bed_form(rendered = rendered,
44                                 psm = psm,
45                                 mode = mode,
46                                 formaction = "book_reserved_bed",
47                                 button = "Reserve Bed",
48                                 ds = ds,
49                                 )
50elif psm == 'valid':
51    pass
52#from Products.zdb import set_trace;set_trace()
53hall_id = context.getId()
54doc = context.getContent()
55student = ds.get('student')
56sid = ds.get('student_id')
57br = ds.get('block_room')
58block = br[0]
59bl = ds.get('bed_letter')
60bid = "%s_%s_%s" % (hall_id,br,bl)
61res = acco_cat(bed = bid)
62psm = ''
63while True:
64    if not res:
65        psm = "No bed with id %s" % bid
66        break
67    bed_brain = res[0]
68    already = acco_cat(student=sid)
69    if reserve or change:
70        if already and not change:
71            psm = "Student %s already reserved bed %s" % (sid, already[0].bed)
72            break
73        if not bed_brain.bed_type.endswith("reserved"):
74            psm = "Not a reserved bed %s" % bid
75            break
76        if bed_brain.student and not change:
77            psm = "Bed %s already reserved for %s" % (bid,bed_brain.student)
78            break
79        if student.sex and not block in doc.blocks_for_female:
80            psm = "Sex does not match %s" % bid
81            break
82    if release:
83        if not already:
84            psm = "Student %s already has no reserved beds" % (sid, already[0].bed)
85            break
86        if not bed_brain.bed_type.endswith("reserved"):
87            psm = "Not a reserved bed %s" % bid
88            break
89        if not bed_brain.student:
90            psm = "Bed %s not reserved for %s" % (bid,bed_brain.student)
91            break
92    break
93       
94if psm != '':
95    return context.book_reserved_bed_form(rendered = rendered,
96                                 psm = psm,
97                                 mode = mode,
98                                 ds = ds,
99                                 formaction = "book_reserved_bed",
100                                 button = "Reserve Bed",
101                                 )
102if change:
103    for bed in already:
104        acco_cat.modifyRecord(bed=bed.bed,student='')
105       
106students = context.portal_url.getPortalObject().campus.students
107student_obj = getattr(students,sid)
108acco_id = "accommodation_%s" % context.getSessionId()
109if reserve or change:
110    acco_cat.modifyRecord(bed = bid, student = sid)
111    if acco_id in student_obj.objectIds():
112        acco_doc = getattr(student_obj, acco_id).getContent()
113        acco_doc.edit(mapping={'bed': bid})
114    logger.info('"%s","booked reserved bed %s for","%s"' % (member,bid,sid))
115    psm = "Bed reserved for %s %s" % (sid,student.name)
116elif release:
117    acco_cat.modifyRecord(bed=bid,student='')
118    if acco_id in student_obj.objectIds():
119        acco_doc = getattr(student_obj, acco_id).getContent()
120        acco_doc.edit(mapping={'bed': bid + "(removed)"})
121    logger.info('"%s","released reserved bed %s for","%s"' % (member,bid,sid))
122    psm = "Bed %s released for %s" % (sid,student.name)
123   
124mode = 'view'
125return context.book_reserved_bed_form(rendered = "",
126                                 psm = psm,
127                                 mode = mode,
128                                 formaction = "book_reserved_bed",
129                                 button = "Next Reservation",
130                                 ds = ds,
131                                 )
132
Note: See TracBrowser for help on using the repository browser.