[629] | 1 | ##parameters=REQUEST |
---|
[805] | 2 | # $Id: reserve_accommodation.py 942 2006-11-25 21:09:18Z henrik $ |
---|
[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() |
---|
[821] | 13 | validate = REQUEST.has_key("cpsdocument_create_button") |
---|
| 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' |
---|
[942] | 23 | |
---|
| 24 | if info['review_state'] != 'cleared_and_validated': |
---|
| 25 | return context.REQUEST.RESPONSE.redirect("%s/no_booking_allowed" % info['student'].absolute_url()) |
---|
| 26 | |
---|
[742] | 27 | if info.has_key('acco') and info['acco']: |
---|
[821] | 28 | validate = REQUEST.has_key("cpsdocument_edit_button") |
---|
[835] | 29 | if info['acco_review_state'] == "maintenance_fee_paid": |
---|
[742] | 30 | return context.REQUEST.RESPONSE.redirect("%s/accommodation_view" % info['acco'].absolute_url()) |
---|
| 31 | else: |
---|
| 32 | mode = 'edit' |
---|
| 33 | d = {} |
---|
[833] | 34 | button = "Book" |
---|
[742] | 35 | if mode == 'edit': |
---|
| 36 | info = context.getStudentInfo() |
---|
| 37 | d['acco_res_date'] = info['acco_doc'].acco_res_date |
---|
| 38 | d['acco_res_sc_pin'] = info['acco_doc'].acco_res_sc_pin |
---|
[821] | 39 | d['student_status'] = info['acco_doc'].student_status |
---|
[742] | 40 | d['bed'] = info['acco_doc'].bed |
---|
| 41 | d['session'] = info['acco_doc'].session |
---|
[821] | 42 | button = "Pay Maintainance Fee" |
---|
[742] | 43 | res,psm,ds = lt.renderLayout(layout_id= 'student_accommodation_fe', |
---|
[686] | 44 | schema_id= 'student_accommodation', |
---|
[629] | 45 | context=context, |
---|
| 46 | mapping=validate and REQUEST, |
---|
[742] | 47 | ob=d, |
---|
| 48 | layout_mode=mode, |
---|
[652] | 49 | formaction = "reserve_accommodation", |
---|
[821] | 50 | button = button |
---|
[629] | 51 | ) |
---|
| 52 | if psm == 'invalid': |
---|
[849] | 53 | return context.accommodation_pin_edit_form(rendered = res, |
---|
[892] | 54 | psm = "Please correct your input!", |
---|
[701] | 55 | #psm = "%s, %s" % (psm,ds), |
---|
[821] | 56 | mode = mode, |
---|
[629] | 57 | ds = ds, |
---|
| 58 | ) |
---|
| 59 | elif psm == '': |
---|
[849] | 60 | return context.accommodation_pin_edit_form(rendered = res, |
---|
[629] | 61 | psm = None, |
---|
[821] | 62 | mode = mode, |
---|
[629] | 63 | ds = ds, |
---|
| 64 | ) |
---|
| 65 | elif psm == 'valid': |
---|
| 66 | s_id = ds.get('s_id') |
---|
[742] | 67 | if mode == 'create': |
---|
| 68 | pin = str(ds.get('acco_res_sc_pin')) |
---|
| 69 | pa = context.portal_accommodation |
---|
| 70 | code,bed = pa.searchAndReserveBed(s_id,"%s_%s" % (info['sex'],ds.get('student_status'))) |
---|
| 71 | if code < 0: |
---|
[855] | 72 | return context.accommodation_pin_edit_form(rendered = res, |
---|
[635] | 73 | psm = bed, |
---|
[821] | 74 | mode = mode, |
---|
[635] | 75 | ds = ds, |
---|
| 76 | ) |
---|
[742] | 77 | student.invokeFactory('StudentAccommodation',acco_id) |
---|
| 78 | acco = getattr(student,acco_id) |
---|
[828] | 79 | acco_info = context.waeup_tool.getAccommodationInfo(bed) |
---|
| 80 | ds.set('acco_maint_code', acco_info.get('maintenance_code')) |
---|
| 81 | ds.set('acco_maint_fee', acco_info.get('maintenance_fee')) |
---|
[742] | 82 | ds.set('acco_res_date', current) |
---|
| 83 | ds.set('bed', bed) |
---|
| 84 | ds.set('session', session) |
---|
| 85 | acco.getContent().edit(mapping=ds) |
---|
[744] | 86 | #wftool.doActionFor(acco,'pay_maintenance_fee',dest_container=acco) |
---|
[856] | 87 | return context.REQUEST.RESPONSE.redirect("%s/reserve_accommodation" % student.absolute_url()) |
---|
[742] | 88 | pin = str(ds.get('acco_main_sc_pin')) |
---|
| 89 | pp = context.portal_pins |
---|
[639] | 90 | acco = getattr(student,acco_id) |
---|
[742] | 91 | ds.set('acco_maint_date', current) |
---|
[639] | 92 | acco.getContent().edit(mapping=ds) |
---|
[744] | 93 | wftool.doActionFor(acco,'pay_maintenance_fee',dest_container=acco) |
---|
[660] | 94 | return context.REQUEST.RESPONSE.redirect("%s/accommodation_view" % student.absolute_url()) |
---|