[629] | 1 | ##parameters=REQUEST |
---|
[805] | 2 | # $Id: reserve_accommodation.py 805 2006-11-09 09:38:29Z joachim $ |
---|
[629] | 3 | """ |
---|
| 4 | process the Application Form |
---|
| 5 | return html renderer + psm |
---|
| 6 | """ |
---|
| 7 | import DateTime |
---|
| 8 | current = DateTime.DateTime() |
---|
| 9 | pr = context.portal_registration |
---|
[659] | 10 | wftool = context.portal_workflow |
---|
[629] | 11 | |
---|
[635] | 12 | info = context.getStudentInfo() |
---|
[742] | 13 | validate = REQUEST.has_key("cpsdocument_create_button") or\ |
---|
| 14 | REQUEST.has_key("cpsdocument_edit_button") |
---|
[629] | 15 | |
---|
| 16 | lt = context.portal_layouts |
---|
| 17 | pr = context.portal_registration |
---|
[639] | 18 | session = current.year() |
---|
[659] | 19 | acco_id = 'accommodation_%s' % session |
---|
[639] | 20 | info = context.getStudentInfo() |
---|
| 21 | student = info['student'] |
---|
[742] | 22 | mode = 'create' |
---|
| 23 | if info.has_key('acco') and info['acco']: |
---|
[744] | 24 | if info['acco_review_state'] == "maintenance_fee_payed": |
---|
[742] | 25 | return context.REQUEST.RESPONSE.redirect("%s/accommodation_view" % info['acco'].absolute_url()) |
---|
| 26 | else: |
---|
| 27 | mode = 'edit' |
---|
| 28 | d = {} |
---|
| 29 | if mode == 'edit': |
---|
| 30 | info = context.getStudentInfo() |
---|
| 31 | d['acco_res_date'] = info['acco_doc'].acco_res_date |
---|
| 32 | d['acco_res_sc_pin'] = info['acco_doc'].acco_res_sc_pin |
---|
| 33 | d['bed'] = info['acco_doc'].bed |
---|
| 34 | d['session'] = info['acco_doc'].session |
---|
| 35 | res,psm,ds = lt.renderLayout(layout_id= 'student_accommodation_fe', |
---|
[686] | 36 | schema_id= 'student_accommodation', |
---|
[629] | 37 | context=context, |
---|
| 38 | mapping=validate and REQUEST, |
---|
[742] | 39 | ob=d, |
---|
| 40 | layout_mode=mode, |
---|
[652] | 41 | formaction = "reserve_accommodation", |
---|
[659] | 42 | button = "Book", |
---|
[629] | 43 | ) |
---|
| 44 | if psm == 'invalid': |
---|
[652] | 45 | return context.accommodation_pin_form(rendered = res, |
---|
[701] | 46 | psm = "Please correct your input.", |
---|
| 47 | #psm = "%s, %s" % (psm,ds), |
---|
[629] | 48 | firstlayout = True, |
---|
| 49 | lastlayout = True, |
---|
| 50 | ds = ds, |
---|
| 51 | ) |
---|
| 52 | elif psm == '': |
---|
[652] | 53 | return context.accommodation_pin_form(rendered = res, |
---|
[629] | 54 | psm = None, |
---|
| 55 | firstlayout = True, |
---|
| 56 | lastlayout = True, |
---|
| 57 | ds = ds, |
---|
| 58 | ) |
---|
| 59 | elif psm == 'valid': |
---|
| 60 | s_id = ds.get('s_id') |
---|
[742] | 61 | if mode == 'create': |
---|
| 62 | pin = str(ds.get('acco_res_sc_pin')) |
---|
| 63 | pa = context.portal_accommodation |
---|
| 64 | code,bed = pa.searchAndReserveBed(s_id,"%s_%s" % (info['sex'],ds.get('student_status'))) |
---|
| 65 | if code < 0: |
---|
| 66 | return context.accommodation_pin_form(rendered = res, |
---|
[635] | 67 | psm = bed, |
---|
| 68 | firstlayout = True, |
---|
| 69 | lastlayout = True, |
---|
| 70 | ds = ds, |
---|
| 71 | ) |
---|
[742] | 72 | student.invokeFactory('StudentAccommodation',acco_id) |
---|
| 73 | acco = getattr(student,acco_id) |
---|
| 74 | ds.set('acco_res_date', current) |
---|
| 75 | ds.set('bed', bed) |
---|
| 76 | ds.set('session', session) |
---|
| 77 | acco.getContent().edit(mapping=ds) |
---|
[744] | 78 | #wftool.doActionFor(acco,'pay_maintenance_fee',dest_container=acco) |
---|
[742] | 79 | return context.REQUEST.RESPONSE.redirect("%s/accommodation_view" % student.absolute_url()) |
---|
| 80 | pin = str(ds.get('acco_main_sc_pin')) |
---|
| 81 | pp = context.portal_pins |
---|
[639] | 82 | acco = getattr(student,acco_id) |
---|
[742] | 83 | ds.set('acco_maint_date', current) |
---|
[639] | 84 | acco.getContent().edit(mapping=ds) |
---|
[744] | 85 | wftool.doActionFor(acco,'pay_maintenance_fee',dest_container=acco) |
---|
[660] | 86 | return context.REQUEST.RESPONSE.redirect("%s/accommodation_view" % student.absolute_url()) |
---|
[742] | 87 | |
---|
[652] | 88 | ##return context.accommodation_pin_form(rendered = res, |
---|
[642] | 89 | ## psm = "successfully reserved bed %s" % bed, |
---|
| 90 | ## firstlayout = True, |
---|
| 91 | ## lastlayout = True, |
---|
| 92 | ## ds = ds, |
---|
| 93 | ## ) |
---|
[629] | 94 | |
---|