source: WAeUP_SRP/trunk/skins/waeup_student/reserve_accommodation.py @ 1037

Last change on this file since 1037 was 952, checked in by joachim, 18 years ago

loading of cps_portlets by generic_setup

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