##parameters=REQUEST # $Id: book_reserved_bed.py 1426 2007-02-15 20:59:20Z henrik $ """ process the the accommodation reservation """ import DateTime current = DateTime.DateTime() pr = context.portal_registration wftool = context.portal_workflow lt = context.portal_layouts mtool = context.portal_membership member = mtool.getAuthenticatedMember() acco_cat = context.portal_accommodation import logging logger = logging.getLogger('Accommodation.BookReservedBed') mode = 'create' validate = REQUEST.has_key("cpsdocument_edit_button") and\ REQUEST.get("cpsdocument_edit_button").startswith('Reserve') d = {} rendered,psm,ds = lt.renderLayout(layout_id= 'acco_bed_booking', schema_id= 'acco_bed_booking', context=context, mapping=validate and REQUEST, ob=d, layout_mode='edit', commit = False ) if psm == 'invalid': psm = "Please correct your input." return context.book_reserved_bed_form(rendered = rendered, psm = psm, #psm = "%s, %s" % (psm,ds), mode = mode, formaction = "book_reserved_bed", button = "Reserve Bed", ds = ds, ) elif psm == '': return context.book_reserved_bed_form(rendered = rendered, psm = psm, mode = mode, formaction = "book_reserved_bed", button = "Reserve Bed", ds = ds, ) elif psm == 'valid': pass #from Products.zdb import set_trace;set_trace() hall_id = context.getId() doc = context.getContent() student = ds.get('student') sid = ds.get('student_id') br = ds.get('block_room') block = br[0] bl = ds.get('bed_letter') bid = "%s_%s_%s" % (hall_id,br,bl) res = acco_cat(bed = bid) psm = '' while True: if not res: psm = "No bed with id %s" % bid break bed_brain = res[0] already = acco_cat(student=sid) if already: psm = "Student %s already reserved bed %s" % (sid, already[0].bed) break if not bed_brain.bed_type.endswith("reserved"): psm = "Not a reserved bed %s" % bid break if bed_brain.student: psm = "Bed %s already reserved for %s" % (bid,bed_brain.student) break if student.sex and not block in doc.blocks_for_female: psm = "Sex does not match %s" % bid break break if psm != '': return context.book_reserved_bed_form(rendered = rendered, psm = psm, mode = mode, ds = ds, formaction = "book_reserved_bed", button = "Reserve Bed", ) acco_cat.modifyRecord(bed = bid, student = sid) logger.info('"%s","booked reserved bed %s for","%s"' % (member,bid,sid)) return context.book_reserved_bed_form(rendered = "", psm = "Bed reserved for %s %s" % (sid,student.name), mode = mode, formaction = "book_reserved_bed", button = "Next Reservation", ds = ds, )