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