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