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