##parameters=REQUEST # $Id: reserve_accommodation.py 1100 2006-12-20 09:23:40Z joachim $ """ process the the accommodation reservation """ import DateTime current = DateTime.DateTime() pr = context.portal_registration wftool = context.portal_workflow lt = context.portal_layouts info = context.getAccommodationInfo() student = info['student'] acco_id = info['acco_id'] session = acco_id[-4:] mode = 'create' if info['review_state'] != 'cleared_and_validated': return context.REQUEST.RESPONSE.redirect("%s/no_booking_allowed" % info['student'].absolute_url()) validate = REQUEST.has_key("cpsdocument_create_button") if info.has_key('acco') and info['acco']: validate = REQUEST.has_key("cpsdocument_edit_button") if info['acco_review_state'] == "maintenance_fee_paid": return context.REQUEST.RESPONSE.redirect("%s/accommodation_view" % info['acco'].absolute_url()) else: mode = 'edit' d = {} button = "Book" if mode == 'edit': info = context.getStudentInfo() d['acco_res_date'] = info['acco_doc'].acco_res_date d['acco_res_sc_pin'] = info['acco_doc'].acco_res_sc_pin d['student_status'] = info['acco_doc'].student_status d['bed'] = info['acco_doc'].bed d['session'] = info['acco_doc'].session button = "Pay Maintainance Fee" res,psm,ds = lt.renderLayout(layout_id= 'student_accommodation_fe', schema_id= 'student_accommodation', context=context, mapping=validate and REQUEST, ob=d, layout_mode=mode, formaction = "reserve_accommodation", button = button ) if psm == 'invalid': return context.accommodation_pin_edit_form(rendered = res, psm = "Please correct your input!", #psm = "%s, %s" % (psm,ds), mode = mode, ds = ds, ) elif psm == '': return context.accommodation_pin_edit_form(rendered = res, psm = None, mode = mode, ds = ds, ) elif psm == 'valid': s_id = ds.get('s_id') if mode == 'create': pin = str(ds.get('acco_res_sc_pin')) pa = context.portal_accommodation code,bed = pa.searchAndReserveBed(s_id,"%s" % (info['student_status'])) #code,bed = pa.searchAndReserveBed(s_id,"%s_%s" % (info['sex'],ds.get('student_status'))) if code < 0: return context.accommodation_pin_edit_form(rendered = res, psm = bed, mode = mode, ds = ds, ) student.invokeFactory('StudentAccommodation',acco_id) acco = getattr(student,acco_id) acco_info = context.waeup_tool.getAccommodationInfo(bed) ds.set('acco_maint_code', acco_info.get('maintenance_code')) ds.set('acco_maint_fee', acco_info.get('maintenance_fee')) ds.set('acco_res_date', current) ds.set('bed', bed) ds.set('session', session) ds.set('student_status',info['student_status']) acco.getContent().edit(mapping=ds) #wftool.doActionFor(acco,'pay_maintenance_fee',dest_container=acco) return context.REQUEST.RESPONSE.redirect("%s/reserve_accommodation" % student.absolute_url()) pin = str(ds.get('acco_main_sc_pin')) pp = context.portal_pins acco = getattr(student,acco_id) ds.set('acco_maint_date', current) acco.getContent().edit(mapping=ds) wftool.doActionFor(acco,'pay_maintenance_fee',dest_container=acco) return context.REQUEST.RESPONSE.redirect("%s/accommodation_view" % student.absolute_url())