##parameters=REQUEST # $Id: apply_admission.py 543 2006-09-24 07:44:32Z 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") lt = context.portal_layouts pr = context.portal_registration session = current.year() acco_id = 'accommodation_%s' % session info = context.getStudentInfo() student = info['student'] if info['acco']: return context.REQUEST.RESPONSE.redirect("%s/accommodation_view" % info['acco'].absolute_url()) res,psm,ds = lt.renderLayout(layout_id= 'student_accommodation', schema_id= 'student_accommodation', context=context, mapping=validate and REQUEST, ob={}, layout_mode='create', formaction = "reserve_accommodation", button = "Book", ) if psm == 'invalid': return context.accommodation_pin_form(rendered = res, #psm = "Please correct your input.", psm = "%s, %s" % (psm,ds), firstlayout = True, lastlayout = True, ds = ds, ) elif psm == '': return context.accommodation_pin_form(rendered = res, psm = None, firstlayout = True, lastlayout = True, ds = ds, ) elif psm == 'valid': s_id = ds.get('s_id') pin = str(ds.get('acco_res_ac_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, firstlayout = True, lastlayout = True, ds = ds, ) student.invokeFactory('StudentAccommodation',acco_id) acco = getattr(student,acco_id) wftool.doActionFor(acco,'open',dest_container=acco) ds.set('acco_res_date', current) ds.set('bed', bed) ds.set('session', session) acco.getContent().edit(mapping=ds) return context.REQUEST.RESPONSE.redirect("%s/accommodation_view" % student.absolute_url()) ##return context.accommodation_pin_form(rendered = res, ## psm = "successfully reserved bed %s" % bed, ## firstlayout = True, ## lastlayout = True, ## ds = ds, ## )