1 | ##parameters=REQUEST |
---|
2 | # $Id: apply_admission.py 543 2006-09-24 07:44:32Z 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 | |
---|
15 | lt = context.portal_layouts |
---|
16 | pr = context.portal_registration |
---|
17 | session = current.year() |
---|
18 | acco_id = 'accommodation_%s' % session |
---|
19 | info = context.getStudentInfo() |
---|
20 | student = info['student'] |
---|
21 | if info['acco']: |
---|
22 | return context.REQUEST.RESPONSE.redirect("%s" % info['acco'].absolute_url()) |
---|
23 | res,psm,ds = lt.renderLayout(layout_id= 'student_accommodation_fe', |
---|
24 | schema_id= 'student_accommodation_fe', |
---|
25 | context=context, |
---|
26 | mapping=validate and REQUEST, |
---|
27 | ob={}, |
---|
28 | layout_mode='create', |
---|
29 | formaction = "reserve_accommodation", |
---|
30 | button = "Book", |
---|
31 | ) |
---|
32 | if psm == 'invalid': |
---|
33 | return context.accommodation_pin_form(rendered = res, |
---|
34 | #psm = "Please correct your input.", |
---|
35 | psm = "%s, %s" % (psm,ds), |
---|
36 | firstlayout = True, |
---|
37 | lastlayout = True, |
---|
38 | ds = ds, |
---|
39 | ) |
---|
40 | elif psm == '': |
---|
41 | return context.accommodation_pin_form(rendered = res, |
---|
42 | psm = None, |
---|
43 | firstlayout = True, |
---|
44 | lastlayout = True, |
---|
45 | ds = ds, |
---|
46 | ) |
---|
47 | elif psm == 'valid': |
---|
48 | s_id = ds.get('s_id') |
---|
49 | pin = str(ds.get('acco_res_ac_pin')) |
---|
50 | |
---|
51 | pa = context.portal_accommodation |
---|
52 | code,bed = pa.searchAndReserveBed(s_id,"%s_%s" % (info['sex'],ds.get('student_status'))) |
---|
53 | if code < 0: |
---|
54 | return context.accommodation_pin_form(rendered = res, |
---|
55 | psm = bed, |
---|
56 | firstlayout = True, |
---|
57 | lastlayout = True, |
---|
58 | ds = ds, |
---|
59 | ) |
---|
60 | student.invokeFactory('StudentAccommodation',acco_id) |
---|
61 | acco = getattr(student,acco_id) |
---|
62 | wftool.doActionFor(acco,'open',dest_container=acco) |
---|
63 | ds.set('acco_res_date', current) |
---|
64 | ds.set('bed', bed) |
---|
65 | ds.set('session', session) |
---|
66 | acco.getContent().edit(mapping=ds) |
---|
67 | return context.REQUEST.RESPONSE.redirect("%s/accommodation_view" % student.absolute_url()) |
---|
68 | ##return context.accommodation_pin_form(rendered = res, |
---|
69 | ## psm = "successfully reserved bed %s" % bed, |
---|
70 | ## firstlayout = True, |
---|
71 | ## lastlayout = True, |
---|
72 | ## ds = ds, |
---|
73 | ## ) |
---|
74 | |
---|