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