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

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

fix

  • Property svn:keywords set to Id
File size: 5.2 KB
RevLine 
[1393]1##parameters=REQUEST
2# $Id: book_reserved_bed.py 1451 2007-02-20 22:17:41Z 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
[1449]17#change = REQUEST.has_key("reserve_and_change")
18change = False
[1444]19release = REQUEST.has_key("release")
20reserve = REQUEST.has_key("reserve")
21validate = release or change or (reserve and
[1440]22           REQUEST.get("reserve").startswith('Reserve'))
[1393]23mode = 'create'
24d = {}
[1412]25rendered,psm,ds = lt.renderLayout(layout_id= 'acco_bed_booking',
[1393]26                      schema_id= 'acco_bed_booking',
27                      context=context,
28                      mapping=validate and REQUEST,
29                      ob=d,
30                      layout_mode='edit',
31                      commit = False
32                      )
33if psm == 'invalid':
34    psm = "Please correct your input."
[1412]35    return context.book_reserved_bed_form(rendered = rendered,
[1393]36                                 psm = psm,
37                                 #psm = "%s, %s" % (psm,ds),
38                                 mode = mode,
39                                 formaction = "book_reserved_bed",
[1426]40                                 button = "Reserve Bed",
[1393]41                                 ds = ds,
42                                 )
43elif psm == '':
[1412]44    return context.book_reserved_bed_form(rendered = rendered,
[1393]45                                 psm = psm,
46                                 mode = mode,
47                                 formaction = "book_reserved_bed",
[1426]48                                 button = "Reserve Bed",
[1393]49                                 ds = ds,
50                                 )
51elif psm == 'valid':
52    pass
[1412]53#from Products.zdb import set_trace;set_trace()
[1393]54hall_id = context.getId()
55doc = context.getContent()
56student = ds.get('student')
57sid = ds.get('student_id')
58br = ds.get('block_room')
59block = br[0]
60bl = ds.get('bed_letter')
61bid = "%s_%s_%s" % (hall_id,br,bl)
[1410]62res = acco_cat(bed = bid)
[1393]63psm = ''
[1449]64students = context.portal_url.getPortalObject().campus.students
65student_obj = getattr(students,sid)
66acco_id = "accommodation_%s" % context.getSessionId()
[1393]67while True:
68    if not res:
69        psm = "No bed with id %s" % bid
70        break
71    bed_brain = res[0]
[1426]72    already = acco_cat(student=sid)
[1444]73    if reserve or change:
74        if already and not change:
75            psm = "Student %s already reserved bed %s" % (sid, already[0].bed)
76            break
77        if not bed_brain.bed_type.endswith("reserved"):
[1446]78            psm = "Not a reserved bed: %s" % bid
[1444]79            break
80        if bed_brain.student and not change:
81            psm = "Bed %s already reserved for %s" % (bid,bed_brain.student)
82            break
83        if student.sex and not block in doc.blocks_for_female:
84            psm = "Sex does not match %s" % bid
85            break
86    if release:
[1449]87        if acco_id in student_obj.objectIds():
88            acco_doc = getattr(student_obj, acco_id).getContent()
[1450]89            if acco_doc.bed != bid:
90                psm = "Student %s has not reserved bed %s" % (sid, bid)
[1449]91                break
[1444]92        if not already:
93            psm = "Student %s already has no reserved beds" % (sid, already[0].bed)
94            break
95        if not bed_brain.bed_type.endswith("reserved"):
[1446]96            psm = "Not a reserved bed: %s" % bid
[1444]97            break
98        if not bed_brain.student:
99            psm = "Bed %s not reserved for %s" % (bid,bed_brain.student)
100            break
[1393]101    break
[1446]102
[1393]103if psm != '':
[1412]104    return context.book_reserved_bed_form(rendered = rendered,
[1393]105                                 psm = psm,
106                                 mode = mode,
107                                 ds = ds,
108                                 formaction = "book_reserved_bed",
[1426]109                                 button = "Reserve Bed",
[1393]110                                 )
[1444]111if change:
[1440]112    for bed in already:
113        acco_cat.modifyRecord(bed=bed.bed,student='')
[1446]114
[1444]115if reserve or change:
116    acco_cat.modifyRecord(bed = bid, student = sid)
117    if acco_id in student_obj.objectIds():
118        acco_doc = getattr(student_obj, acco_id).getContent()
119        acco_doc.edit(mapping={'bed': bid})
120    logger.info('"%s","booked reserved bed %s for","%s"' % (member,bid,sid))
[1450]121    psm = "Bed %s reserved for %s %s" % (bid,sid,student.name)
[1444]122elif release:
[1451]123    modify = False
[1444]124    if acco_id in student_obj.objectIds():
125        acco_doc = getattr(student_obj, acco_id).getContent()
[1449]126        if acco_doc.bed != bid:
[1451]127            modify = True
128    else:
129        modify = True
130    if modify:
131        acco_cat.modifyRecord(bed=bid,student='')
132        logger.info('"%s","cancelled reservation %s by","%s"' % (member,bid,sid))
133        psm = "%s removed from %s" % (student.name,bid)
134    else:
135        psm = "%s removing failed for %s" % (student.name,bid)
136       
[1440]137mode = 'view'
[1412]138return context.book_reserved_bed_form(rendered = "",
[1444]139                                 psm = psm,
[1393]140                                 mode = mode,
141                                 formaction = "book_reserved_bed",
[1426]142                                 button = "Next Reservation",
[1393]143                                 ds = ds,
144                                 )
145
Note: See TracBrowser for help on using the repository browser.