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

Last change on this file since 942 was 942, checked in by Henrik Bettermann, 18 years ago

reserve_accommodation only allowed for cleared_and_validated
several bugs fixed

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