##parameters=REQUEST # $Id: book_reserved_bed.py 1440 2007-02-19 15:06:06Z joachim $ """ 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') change_bed = REQUEST.has_key("reserve_and_change") validate = change_bed or (REQUEST.has_key("reserve") and REQUEST.get("reserve").startswith('Reserve')) mode = 'create' 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 and not change_bed: 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 and not change_bed: 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", ) if change_bed: for bed in already: acco_cat.modifyRecord(bed=bed.bed,student='') acco_cat.modifyRecord(bed = bid, student = sid) students = context.portal_url.getPortalObject().campus.students student_obj = getattr(students,sid) acco_id = "accommodation_%s" % context.getSessionId() if acco_id in student_obj.objectIds(): acco_doc = getattr(student_obj, acco_id).getContent() acco_doc.edit(mapping={'bed': bid}) logger.info('"%s","booked reserved bed %s for","%s"' % (member,bid,sid)) mode = 'view' 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, )