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