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

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

new method book_reserved_bed to book a reserved bed for a student

  • Property svn:keywords set to Id
File size: 3.2 KB
Line 
1##parameters=REQUEST
2# $Id: book_reserved_bed.py 1393 2007-02-05 21:42:08Z 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')
16
17mode = 'create'
18validate = REQUEST.has_key("cpsdocument_edit_button")
19d = {}
20res,psm,ds = lt.renderLayout(layout_id= 'acco_bed_booking',
21                      schema_id= 'acco_bed_booking',
22                      context=context,
23                      mapping=validate and REQUEST,
24                      ob=d,
25                      layout_mode='edit',
26                      commit = False
27                      )
28if psm == 'invalid':
29    psm = "Please correct your input."
30    return context.book_reserved_bed_form(rendered = res,
31                                 psm = psm,
32                                 #psm = "%s, %s" % (psm,ds),
33                                 mode = mode,
34                                 formaction = "book_reserved_bed",
35                                 button = "reserve bed",
36                                 ds = ds,
37                                 )
38elif psm == '':
39    return context.book_reserved_bed_form(rendered = res,
40                                 psm = psm,
41                                 mode = mode,
42                                 formaction = "book_reserved_bed",
43                                 button = "reserve bed",
44                                 ds = ds,
45                                 )
46elif psm == 'valid':
47    pass
48hall_id = context.getId()
49doc = context.getContent()
50student = ds.get('student')
51sid = ds.get('student_id')
52br = ds.get('block_room')
53block = br[0]
54bl = ds.get('bed_letter')
55bid = "%s_%s_%s" % (hall_id,br,bl)
56res = acco_cat(bed = bed)
57psm = ''
58while True:
59    if not res:
60        psm = "No bed with id %s" % bid
61        break
62    bed_brain = res[0]
63    if not bed_brain.bed_type.endswith("reserved"):
64        psm = "Not a reserved bed %s" % bid
65        break
66    if bed_brain.student:
67        psm = "Bed %s already reserved for %s" % (bid,bed_brain.student)
68        break
69    if student.sex and not block in doc.blocks_for_female:
70        psm = "Sex does not match %s" % bid
71        break
72    break
73if psm != '':
74    return context.book_reserved_bed_form(rendered = res,
75                                 psm = psm,
76                                 mode = mode,
77                                 ds = ds,
78                                 formaction = "book_reserved_bed",
79                                 button = "reserve bed",
80                                 )
81acco_cat.modifyRecord(bed = bed, student = sid)
82logger.info('"%s","booked reserved bed %s for","%s"' % (member,bed,sid))
83return context.book_reserved_bed_form(rendered = res,
84                                 psm = "Bed reserved for %s %s" % (sid,student.name),
85                                 mode = mode,
86                                 formaction = "book_reserved_bed",
87                                 button = "reserve bed",
88                                 ds = ds,
89                                 )
90
Note: See TracBrowser for help on using the repository browser.