1 | ##parameters=REQUEST |
---|
2 | # $Id: reserve_accommodation.py 805 2006-11-09 09:38:29Z joachim $ |
---|
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") or\ |
---|
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 | if info['acco_review_state'] == "maintenance_fee_payed": |
---|
25 | return context.REQUEST.RESPONSE.redirect("%s/accommodation_view" % info['acco'].absolute_url()) |
---|
26 | else: |
---|
27 | mode = 'edit' |
---|
28 | d = {} |
---|
29 | if mode == 'edit': |
---|
30 | info = context.getStudentInfo() |
---|
31 | d['acco_res_date'] = info['acco_doc'].acco_res_date |
---|
32 | d['acco_res_sc_pin'] = info['acco_doc'].acco_res_sc_pin |
---|
33 | d['bed'] = info['acco_doc'].bed |
---|
34 | d['session'] = info['acco_doc'].session |
---|
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 = "Book", |
---|
43 | ) |
---|
44 | if psm == 'invalid': |
---|
45 | return context.accommodation_pin_form(rendered = res, |
---|
46 | psm = "Please correct your input.", |
---|
47 | #psm = "%s, %s" % (psm,ds), |
---|
48 | firstlayout = True, |
---|
49 | lastlayout = True, |
---|
50 | ds = ds, |
---|
51 | ) |
---|
52 | elif psm == '': |
---|
53 | return context.accommodation_pin_form(rendered = res, |
---|
54 | psm = None, |
---|
55 | firstlayout = True, |
---|
56 | lastlayout = True, |
---|
57 | ds = ds, |
---|
58 | ) |
---|
59 | elif psm == 'valid': |
---|
60 | s_id = ds.get('s_id') |
---|
61 | if mode == 'create': |
---|
62 | pin = str(ds.get('acco_res_sc_pin')) |
---|
63 | pa = context.portal_accommodation |
---|
64 | code,bed = pa.searchAndReserveBed(s_id,"%s_%s" % (info['sex'],ds.get('student_status'))) |
---|
65 | if code < 0: |
---|
66 | return context.accommodation_pin_form(rendered = res, |
---|
67 | psm = bed, |
---|
68 | firstlayout = True, |
---|
69 | lastlayout = True, |
---|
70 | ds = ds, |
---|
71 | ) |
---|
72 | student.invokeFactory('StudentAccommodation',acco_id) |
---|
73 | acco = getattr(student,acco_id) |
---|
74 | ds.set('acco_res_date', current) |
---|
75 | ds.set('bed', bed) |
---|
76 | ds.set('session', session) |
---|
77 | acco.getContent().edit(mapping=ds) |
---|
78 | #wftool.doActionFor(acco,'pay_maintenance_fee',dest_container=acco) |
---|
79 | return context.REQUEST.RESPONSE.redirect("%s/accommodation_view" % student.absolute_url()) |
---|
80 | pin = str(ds.get('acco_main_sc_pin')) |
---|
81 | pp = context.portal_pins |
---|
82 | acco = getattr(student,acco_id) |
---|
83 | ds.set('acco_maint_date', current) |
---|
84 | acco.getContent().edit(mapping=ds) |
---|
85 | wftool.doActionFor(acco,'pay_maintenance_fee',dest_container=acco) |
---|
86 | return context.REQUEST.RESPONSE.redirect("%s/accommodation_view" % student.absolute_url()) |
---|
87 | |
---|
88 | ##return context.accommodation_pin_form(rendered = res, |
---|
89 | ## psm = "successfully reserved bed %s" % bed, |
---|
90 | ## firstlayout = True, |
---|
91 | ## lastlayout = True, |
---|
92 | ## ds = ds, |
---|
93 | ## ) |
---|
94 | |
---|