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
RevLine 
[1393]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
[1426]15logger = logging.getLogger('Accommodation.BookReservedBed')
[1393]16
[1440]17change_bed = REQUEST.has_key("reserve_and_change")
18validate = change_bed or (REQUEST.has_key("reserve") and
19           REQUEST.get("reserve").startswith('Reserve'))
[1393]20mode = 'create'
[1440]21
[1393]22d = {}
[1412]23rendered,psm,ds = lt.renderLayout(layout_id= 'acco_bed_booking',
[1393]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."
[1412]33    return context.book_reserved_bed_form(rendered = rendered,
[1393]34                                 psm = psm,
35                                 #psm = "%s, %s" % (psm,ds),
36                                 mode = mode,
37                                 formaction = "book_reserved_bed",
[1426]38                                 button = "Reserve Bed",
[1393]39                                 ds = ds,
40                                 )
41elif psm == '':
[1412]42    return context.book_reserved_bed_form(rendered = rendered,
[1393]43                                 psm = psm,
44                                 mode = mode,
45                                 formaction = "book_reserved_bed",
[1426]46                                 button = "Reserve Bed",
[1393]47                                 ds = ds,
48                                 )
49elif psm == 'valid':
50    pass
[1412]51#from Products.zdb import set_trace;set_trace()
[1393]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)
[1410]60res = acco_cat(bed = bid)
[1393]61psm = ''
62while True:
63    if not res:
64        psm = "No bed with id %s" % bid
65        break
66    bed_brain = res[0]
[1426]67    already = acco_cat(student=sid)
[1440]68    if already and not change_bed:
[1412]69        psm = "Student %s already reserved bed %s" % (sid, already[0].bed)
70        break
[1393]71    if not bed_brain.bed_type.endswith("reserved"):
72        psm = "Not a reserved bed %s" % bid
73        break
[1440]74    if bed_brain.student and not change_bed:
[1393]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 != '':
[1412]82    return context.book_reserved_bed_form(rendered = rendered,
[1393]83                                 psm = psm,
84                                 mode = mode,
85                                 ds = ds,
86                                 formaction = "book_reserved_bed",
[1426]87                                 button = "Reserve Bed",
[1393]88                                 )
[1440]89if change_bed:
90    for bed in already:
91        acco_cat.modifyRecord(bed=bed.bed,student='')
92       
[1410]93acco_cat.modifyRecord(bed = bid, student = sid)
[1440]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})
[1412]100logger.info('"%s","booked reserved bed %s for","%s"' % (member,bid,sid))
[1440]101mode = 'view'
[1412]102return context.book_reserved_bed_form(rendered = "",
[1393]103                                 psm = "Bed reserved for %s %s" % (sid,student.name),
104                                 mode = mode,
105                                 formaction = "book_reserved_bed",
[1426]106                                 button = "Next Reservation",
[1393]107                                 ds = ds,
108                                 )
109
Note: See TracBrowser for help on using the repository browser.