[2857] | 1 | ## Script (Python) "reserve_accommodation.py" |
---|
| 2 | ##bind container=container |
---|
| 3 | ##bind context=context |
---|
| 4 | ##bind namespace= |
---|
| 5 | ##bind script=script |
---|
| 6 | ##bind subpath=traverse_subpath |
---|
[629] | 7 | ##parameters=REQUEST |
---|
[805] | 8 | # $Id: reserve_accommodation.py 2912 2007-12-10 20:11:24Z henrik $ |
---|
[629] | 9 | """ |
---|
[1100] | 10 | process the the accommodation reservation |
---|
[629] | 11 | """ |
---|
[2857] | 12 | try: |
---|
| 13 | from Products.zdb import set_trace |
---|
| 14 | except: |
---|
| 15 | def set_trace(): |
---|
| 16 | pass |
---|
[629] | 17 | import DateTime |
---|
| 18 | current = DateTime.DateTime() |
---|
| 19 | pr = context.portal_registration |
---|
[659] | 20 | wftool = context.portal_workflow |
---|
[629] | 21 | lt = context.portal_layouts |
---|
[1100] | 22 | info = context.getAccommodationInfo() |
---|
[1133] | 23 | |
---|
[1140] | 24 | import logging |
---|
[1566] | 25 | logger = logging.getLogger('Skins.reserve_accommodation') |
---|
[1140] | 26 | |
---|
| 27 | #if info is None: |
---|
| 28 | # return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) |
---|
| 29 | |
---|
[1133] | 30 | if info is None: |
---|
[1140] | 31 | member_id = str(context.portal_membership.getAuthenticatedMember()) |
---|
[1566] | 32 | logger.info('%s tried to reserve accommodation' % (member_id)) |
---|
[1140] | 33 | return context.REQUEST.RESPONSE.redirect("%s/srp_invalid_access" % context.portal_url()) |
---|
[1133] | 34 | |
---|
[1183] | 35 | mode = 'create' |
---|
| 36 | if not info['booking_allowed']: |
---|
| 37 | return context.REQUEST.RESPONSE.redirect("%s/no_booking_allowed" % info['student'].absolute_url()) |
---|
[639] | 38 | student = info['student'] |
---|
[2857] | 39 | student_id = info['student_id'] |
---|
[1100] | 40 | acco_id = info['acco_id'] |
---|
[2857] | 41 | #session = info['session'][1] |
---|
[2912] | 42 | session = info['session'][0] |
---|
| 43 | |
---|
[1100] | 44 | validate = REQUEST.has_key("cpsdocument_create_button") |
---|
[742] | 45 | if info.has_key('acco') and info['acco']: |
---|
[821] | 46 | validate = REQUEST.has_key("cpsdocument_edit_button") |
---|
[2857] | 47 | if info['maintenance_paid']: |
---|
[742] | 48 | return context.REQUEST.RESPONSE.redirect("%s/accommodation_view" % info['acco'].absolute_url()) |
---|
[2887] | 49 | # elif info['online_payment']: |
---|
| 50 | # return context.REQUEST.RESPONSE.redirect("%s/accommodation_view" % info['acco'].absolute_url()) |
---|
| 51 | # # return context.REQUEST.RESPONSE.redirect("%s/pay_interswitch_acco?paytype=HOM" % info['student'].absolute_url()) |
---|
[742] | 52 | else: |
---|
| 53 | mode = 'edit' |
---|
| 54 | d = {} |
---|
[833] | 55 | button = "Book" |
---|
[742] | 56 | if mode == 'edit': |
---|
| 57 | d['acco_res_date'] = info['acco_doc'].acco_res_date |
---|
| 58 | d['acco_res_sc_pin'] = info['acco_doc'].acco_res_sc_pin |
---|
[821] | 59 | d['student_status'] = info['acco_doc'].student_status |
---|
[742] | 60 | d['bed'] = info['acco_doc'].bed |
---|
| 61 | d['session'] = info['acco_doc'].session |
---|
[821] | 62 | button = "Pay Maintainance Fee" |
---|
[742] | 63 | res,psm,ds = lt.renderLayout(layout_id= 'student_accommodation_fe', |
---|
[686] | 64 | schema_id= 'student_accommodation', |
---|
[629] | 65 | context=context, |
---|
| 66 | mapping=validate and REQUEST, |
---|
[742] | 67 | ob=d, |
---|
| 68 | layout_mode=mode, |
---|
[652] | 69 | formaction = "reserve_accommodation", |
---|
[821] | 70 | button = button |
---|
[629] | 71 | ) |
---|
[1255] | 72 | if psm == 'invalid' or info['error'] is not None: |
---|
| 73 | member_id = str(context.portal_membership.getAuthenticatedMember()) |
---|
[1566] | 74 | logger.info('%s, %s' % (member_id,info['error'] )) |
---|
[1255] | 75 | if psm == 'invalid': |
---|
[1293] | 76 | psm = "Please correct your input." |
---|
[1255] | 77 | else: |
---|
[1293] | 78 | psm = "Error in data, unable to reserve bed." |
---|
[2857] | 79 | return context.accommodation_edit_form(rendered = res, |
---|
[1292] | 80 | psm = psm, |
---|
[701] | 81 | #psm = "%s, %s" % (psm,ds), |
---|
[821] | 82 | mode = mode, |
---|
[629] | 83 | ds = ds, |
---|
| 84 | ) |
---|
| 85 | elif psm == '': |
---|
[2857] | 86 | return context.accommodation_edit_form(rendered = res, |
---|
[629] | 87 | psm = None, |
---|
[821] | 88 | mode = mode, |
---|
[629] | 89 | ds = ds, |
---|
| 90 | ) |
---|
| 91 | elif psm == 'valid': |
---|
[742] | 92 | if mode == 'create': |
---|
[2867] | 93 | #set_trace() |
---|
[742] | 94 | pin = str(ds.get('acco_res_sc_pin')) |
---|
[2857] | 95 | code,bed = context.portal_accommodation.searchAndReserveBed(student_id, |
---|
| 96 | "%s" % (info['student_status'])) |
---|
| 97 | while True: |
---|
| 98 | if code == 1: |
---|
| 99 | break |
---|
[1412] | 100 | if code == -1: |
---|
[2857] | 101 | return context.accommodation_edit_form(rendered = res, |
---|
| 102 | psm = "%s" % bed, |
---|
| 103 | mode = mode, |
---|
| 104 | ds = ds, |
---|
| 105 | ) |
---|
[1412] | 106 | elif code == -2: |
---|
[2857] | 107 | return context.accommodation_edit_form(rendered = res, |
---|
| 108 | psm = "No bed available. Your category is already fully booked.", |
---|
| 109 | mode = mode, |
---|
| 110 | ds = ds, |
---|
| 111 | ) |
---|
| 112 | else: # unknown error |
---|
| 113 | return context.accommodation_edit_form(rendered = res, |
---|
| 114 | psm = "Unexpected Error!", |
---|
| 115 | mode = mode, |
---|
| 116 | ds = ds, |
---|
| 117 | ) |
---|
[742] | 118 | student.invokeFactory('StudentAccommodation',acco_id) |
---|
[2857] | 119 | hall_info = context.waeup_tool.getHallInfo(bed) |
---|
| 120 | ds.set('acco_maint_code', hall_info.get('maintenance_code')) |
---|
| 121 | ds.set('acco_maint_fee', hall_info.get('maintenance_fee')) |
---|
[742] | 122 | ds.set('acco_res_date', current) |
---|
| 123 | ds.set('bed', bed) |
---|
| 124 | ds.set('session', session) |
---|
[1100] | 125 | ds.set('student_status',info['student_status']) |
---|
[2857] | 126 | acco = getattr(student,acco_id) |
---|
[742] | 127 | acco.getContent().edit(mapping=ds) |
---|
[744] | 128 | #wftool.doActionFor(acco,'pay_maintenance_fee',dest_container=acco) |
---|
[856] | 129 | return context.REQUEST.RESPONSE.redirect("%s/reserve_accommodation" % student.absolute_url()) |
---|
[742] | 130 | pin = str(ds.get('acco_main_sc_pin')) |
---|
| 131 | pp = context.portal_pins |
---|
[639] | 132 | acco = getattr(student,acco_id) |
---|
[742] | 133 | ds.set('acco_maint_date', current) |
---|
[639] | 134 | acco.getContent().edit(mapping=ds) |
---|
[744] | 135 | wftool.doActionFor(acco,'pay_maintenance_fee',dest_container=acco) |
---|
[660] | 136 | return context.REQUEST.RESPONSE.redirect("%s/accommodation_view" % student.absolute_url()) |
---|
[1292] | 137 | |
---|