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

Last change on this file since 1123 was 1100, checked in by joachim, 18 years ago

reserve accommodation respects ekenhuan campus

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