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