1 | ##parameters=REQUEST |
---|
2 | # $Id: reserve_accommodation.py 1161 2006-12-31 07:50:50Z henrik $ |
---|
3 | """ |
---|
4 | process the the accommodation reservation |
---|
5 | """ |
---|
6 | import DateTime |
---|
7 | current = DateTime.DateTime() |
---|
8 | pr = context.portal_registration |
---|
9 | wftool = context.portal_workflow |
---|
10 | lt = context.portal_layouts |
---|
11 | info = context.getAccommodationInfo() |
---|
12 | |
---|
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 | |
---|
19 | if info is None: |
---|
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()) |
---|
23 | |
---|
24 | student = info['student'] |
---|
25 | acco_id = info['acco_id'] |
---|
26 | session = acco_id[-4:] |
---|
27 | mode = 'create' |
---|
28 | if info['review_state'] != 'cleared_and_validated': |
---|
29 | return context.REQUEST.RESPONSE.redirect("%s/no_booking_allowed" % info['student'].absolute_url()) |
---|
30 | validate = REQUEST.has_key("cpsdocument_create_button") |
---|
31 | if info.has_key('acco') and info['acco']: |
---|
32 | validate = REQUEST.has_key("cpsdocument_edit_button") |
---|
33 | if info['acco_review_state'] == "maintenance_fee_paid": |
---|
34 | return context.REQUEST.RESPONSE.redirect("%s/accommodation_view" % info['acco'].absolute_url()) |
---|
35 | else: |
---|
36 | mode = 'edit' |
---|
37 | d = {} |
---|
38 | button = "Book" |
---|
39 | if mode == 'edit': |
---|
40 | d['acco_res_date'] = info['acco_doc'].acco_res_date |
---|
41 | d['acco_res_sc_pin'] = info['acco_doc'].acco_res_sc_pin |
---|
42 | d['student_status'] = info['acco_doc'].student_status |
---|
43 | d['bed'] = info['acco_doc'].bed |
---|
44 | d['session'] = info['acco_doc'].session |
---|
45 | button = "Pay Maintainance Fee" |
---|
46 | res,psm,ds = lt.renderLayout(layout_id= 'student_accommodation_fe', |
---|
47 | schema_id= 'student_accommodation', |
---|
48 | context=context, |
---|
49 | mapping=validate and REQUEST, |
---|
50 | ob=d, |
---|
51 | layout_mode=mode, |
---|
52 | formaction = "reserve_accommodation", |
---|
53 | button = button |
---|
54 | ) |
---|
55 | if psm == 'invalid': |
---|
56 | return context.accommodation_pin_edit_form(rendered = res, |
---|
57 | psm = "Please correct your input!", |
---|
58 | #psm = "%s, %s" % (psm,ds), |
---|
59 | mode = mode, |
---|
60 | ds = ds, |
---|
61 | ) |
---|
62 | elif psm == '': |
---|
63 | return context.accommodation_pin_edit_form(rendered = res, |
---|
64 | psm = None, |
---|
65 | mode = mode, |
---|
66 | ds = ds, |
---|
67 | ) |
---|
68 | elif psm == 'valid': |
---|
69 | s_id = ds.get('s_id') |
---|
70 | if mode == 'create': |
---|
71 | pin = str(ds.get('acco_res_sc_pin')) |
---|
72 | pa = context.portal_accommodation |
---|
73 | code,bed = pa.searchAndReserveBed(s_id,"%s" % (info['student_status'])) |
---|
74 | #code,bed = pa.searchAndReserveBed(s_id,"%s_%s" % (info['sex'],ds.get('student_status'))) |
---|
75 | if code < 0: |
---|
76 | return context.accommodation_pin_edit_form(rendered = res, |
---|
77 | psm = bed, |
---|
78 | mode = mode, |
---|
79 | ds = ds, |
---|
80 | ) |
---|
81 | student.invokeFactory('StudentAccommodation',acco_id) |
---|
82 | acco = getattr(student,acco_id) |
---|
83 | acco_info = context.waeup_tool.getAccommodationInfo(bed) |
---|
84 | ds.set('acco_maint_code', acco_info.get('maintenance_code')) |
---|
85 | ds.set('acco_maint_fee', acco_info.get('maintenance_fee')) |
---|
86 | ds.set('acco_res_date', current) |
---|
87 | ds.set('bed', bed) |
---|
88 | ds.set('session', session) |
---|
89 | ds.set('student_status',info['student_status']) |
---|
90 | acco.getContent().edit(mapping=ds) |
---|
91 | #wftool.doActionFor(acco,'pay_maintenance_fee',dest_container=acco) |
---|
92 | return context.REQUEST.RESPONSE.redirect("%s/reserve_accommodation" % student.absolute_url()) |
---|
93 | pin = str(ds.get('acco_main_sc_pin')) |
---|
94 | pp = context.portal_pins |
---|
95 | acco = getattr(student,acco_id) |
---|
96 | ds.set('acco_maint_date', current) |
---|
97 | acco.getContent().edit(mapping=ds) |
---|
98 | wftool.doActionFor(acco,'pay_maintenance_fee',dest_container=acco) |
---|
99 | return context.REQUEST.RESPONSE.redirect("%s/accommodation_view" % student.absolute_url()) |
---|