##parameters=REQUEST # $Id: reserve_accommodation.py 835 2006-11-11 05:24:48Z henrik $ """ process the Application Form return html renderer + psm """ import DateTime current = DateTime.DateTime() pr = context.portal_registration wftool = context.portal_workflow info = context.getStudentInfo() validate = REQUEST.has_key("cpsdocument_create_button") # REQUEST.has_key("cpsdocument_edit_button") lt = context.portal_layouts pr = context.portal_registration session = current.year() acco_id = 'accommodation_%s' % session info = context.getStudentInfo() student = info['student'] mode = 'create' 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_form(rendered = res, psm = "Please correct your input.", #psm = "%s, %s" % (psm,ds), mode = mode, ds = ds, ) elif psm == '': return context.accommodation_pin_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_%s" % (info['sex'],ds.get('student_status'))) if code < 0: return context.accommodation_pin_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) 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()) 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())