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