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