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