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

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

book_reserverved_bed enhanced:

  • reserve and change button added

1.) all beds which are reserved for this student are unreserved.
2.) the selected bed is reserved for this student.
3.) The new bed-koordinate is reflected in the accommodation object.

The reserve functionallity is unchanged.

  • Property svn:keywords set to Id
File size: 3.9 KB
Line 
1##parameters=REQUEST
2# $Id: book_reserved_bed.py 1440 2007-02-19 15:06:06Z 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_bed = REQUEST.has_key("reserve_and_change")
18validate = change_bed or (REQUEST.has_key("reserve") and
19           REQUEST.get("reserve").startswith('Reserve'))
20mode = 'create'
21
22d = {}
23rendered,psm,ds = lt.renderLayout(layout_id= 'acco_bed_booking',
24                      schema_id= 'acco_bed_booking',
25                      context=context,
26                      mapping=validate and REQUEST,
27                      ob=d,
28                      layout_mode='edit',
29                      commit = False
30                      )
31if psm == 'invalid':
32    psm = "Please correct your input."
33    return context.book_reserved_bed_form(rendered = rendered,
34                                 psm = psm,
35                                 #psm = "%s, %s" % (psm,ds),
36                                 mode = mode,
37                                 formaction = "book_reserved_bed",
38                                 button = "Reserve Bed",
39                                 ds = ds,
40                                 )
41elif psm == '':
42    return context.book_reserved_bed_form(rendered = rendered,
43                                 psm = psm,
44                                 mode = mode,
45                                 formaction = "book_reserved_bed",
46                                 button = "Reserve Bed",
47                                 ds = ds,
48                                 )
49elif psm == 'valid':
50    pass
51#from Products.zdb import set_trace;set_trace()
52hall_id = context.getId()
53doc = context.getContent()
54student = ds.get('student')
55sid = ds.get('student_id')
56br = ds.get('block_room')
57block = br[0]
58bl = ds.get('bed_letter')
59bid = "%s_%s_%s" % (hall_id,br,bl)
60res = acco_cat(bed = bid)
61psm = ''
62while True:
63    if not res:
64        psm = "No bed with id %s" % bid
65        break
66    bed_brain = res[0]
67    already = acco_cat(student=sid)
68    if already and not change_bed:
69        psm = "Student %s already reserved bed %s" % (sid, already[0].bed)
70        break
71    if not bed_brain.bed_type.endswith("reserved"):
72        psm = "Not a reserved bed %s" % bid
73        break
74    if bed_brain.student and not change_bed:
75        psm = "Bed %s already reserved for %s" % (bid,bed_brain.student)
76        break
77    if student.sex and not block in doc.blocks_for_female:
78        psm = "Sex does not match %s" % bid
79        break
80    break
81if psm != '':
82    return context.book_reserved_bed_form(rendered = rendered,
83                                 psm = psm,
84                                 mode = mode,
85                                 ds = ds,
86                                 formaction = "book_reserved_bed",
87                                 button = "Reserve Bed",
88                                 )
89if change_bed:
90    for bed in already:
91        acco_cat.modifyRecord(bed=bed.bed,student='')
92       
93acco_cat.modifyRecord(bed = bid, student = sid)
94students = context.portal_url.getPortalObject().campus.students
95student_obj = getattr(students,sid)
96acco_id = "accommodation_%s" % context.getSessionId()
97if acco_id in student_obj.objectIds():
98    acco_doc = getattr(student_obj, acco_id).getContent()
99    acco_doc.edit(mapping={'bed': bid})
100logger.info('"%s","booked reserved bed %s for","%s"' % (member,bid,sid))
101mode = 'view'
102return context.book_reserved_bed_form(rendered = "",
103                                 psm = "Bed reserved for %s %s" % (sid,student.name),
104                                 mode = mode,
105                                 formaction = "book_reserved_bed",
106                                 button = "Next Reservation",
107                                 ds = ds,
108                                 )
109
Note: See TracBrowser for help on using the repository browser.