source: WAeUP_SRP/base/skins/waeup_accommodation/reserve_accommodation.py @ 2713

Last change on this file since 2713 was 2454, checked in by Henrik Bettermann, 17 years ago

rebuild getNextInfo.py completely
fetch session from portal properties.xml
change all scripts using getSessionId
remove StudentCourseResult? relevant code from event services
make pay_by_sc.py and interswitch_cb.py work (rebuild both)

  • Property svn:keywords set to Id
File size: 4.9 KB
Line 
1##parameters=REQUEST
2# $Id: reserve_accommodation.py 2454 2007-10-27 21:53:04Z henrik $
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()
12
13import logging
14logger = logging.getLogger('Skins.reserve_accommodation')
15
16#if info is None:
17#    return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
18
19if info is None:
20    member_id = str(context.portal_membership.getAuthenticatedMember())
21    logger.info('%s tried to reserve accommodation' % (member_id))
22    return context.REQUEST.RESPONSE.redirect("%s/srp_invalid_access" % context.portal_url())
23
24mode = 'create'
25if not info['booking_allowed']:
26    return context.REQUEST.RESPONSE.redirect("%s/no_booking_allowed" % info['student'].absolute_url())
27student = info['student']
28acco_id = info['acco_id']
29session = info['session'][1]
30#session = acco_id[-4:]
31validate = REQUEST.has_key("cpsdocument_create_button")
32if info.has_key('acco') and info['acco']:
33    validate = REQUEST.has_key("cpsdocument_edit_button")
34    if info['acco_review_state'] == "maintenance_fee_paid":
35        return context.REQUEST.RESPONSE.redirect("%s/accommodation_view" % info['acco'].absolute_url())
36    else:
37        mode = 'edit'
38d = {}
39button = "Book"
40if mode == 'edit':
41    d['acco_res_date'] = info['acco_doc'].acco_res_date
42    d['acco_res_sc_pin'] = info['acco_doc'].acco_res_sc_pin
43    d['student_status'] = info['acco_doc'].student_status
44    d['bed'] = info['acco_doc'].bed
45    d['session'] = info['acco_doc'].session
46    button = "Pay Maintainance Fee"
47res,psm,ds = lt.renderLayout(layout_id= 'student_accommodation_fe',
48                      schema_id= 'student_accommodation',
49                      context=context,
50                      mapping=validate and REQUEST,
51                      ob=d,
52                      layout_mode=mode,
53                      formaction = "reserve_accommodation",
54                      button = button
55                      )
56if psm == 'invalid' or info['error'] is not None:
57    member_id = str(context.portal_membership.getAuthenticatedMember())
58    logger.info('%s, %s' % (member_id,info['error'] ))
59    if psm == 'invalid':
60        psm = "Please correct your input."
61    else:
62        psm = "Error in data, unable to reserve bed."
63    return context.accommodation_pin_edit_form(rendered = res,
64                                 psm = psm,
65                                 #psm = "%s, %s" % (psm,ds),
66                                 mode = mode,
67                                 ds = ds,
68                                 )
69elif psm == '':
70    return context.accommodation_pin_edit_form(rendered = res,
71                                 psm = None,
72                                 mode = mode,
73                                 ds = ds,
74                                 )
75elif psm == 'valid':
76    s_id = ds.get('s_id')
77    if mode == 'create':
78        pin = str(ds.get('acco_res_sc_pin'))
79        pa = context.portal_accommodation
80        already = pa(student=s_id)
81        if not already:
82            code,bed = pa.searchAndReserveBed(s_id,"%s" % (info['student_status']))
83            #code,bed = pa.searchAndReserveBed(s_id,"%s_%s" % (info['sex'],ds.get('student_status')))
84            if code == -1:
85                return context.accommodation_pin_edit_form(rendered = res,
86                                     psm = "%s" % bed,
87                                     mode = mode,
88                                     ds = ds,
89                                     )
90            elif code == -2:
91                return context.accommodation_pin_edit_form(rendered = res,
92                                     psm = "No bed available. Your category is already fully booked.",
93                                     mode = mode,
94                                     ds = ds,
95                                     )
96        else:
97            bed = already[0].bed
98        student.invokeFactory('StudentAccommodation',acco_id)
99        acco = getattr(student,acco_id)
100        acco_info = context.waeup_tool.getHallInfo(bed)
101        ds.set('acco_maint_code', acco_info.get('maintenance_code'))
102        ds.set('acco_maint_fee', acco_info.get('maintenance_fee'))
103        ds.set('acco_res_date', current)
104        ds.set('bed', bed)
105        ds.set('session', session)
106        ds.set('student_status',info['student_status'])
107        acco.getContent().edit(mapping=ds)
108        #wftool.doActionFor(acco,'pay_maintenance_fee',dest_container=acco)
109        return context.REQUEST.RESPONSE.redirect("%s/reserve_accommodation" % student.absolute_url())
110pin = str(ds.get('acco_main_sc_pin'))
111pp = context.portal_pins
112acco = getattr(student,acco_id)
113ds.set('acco_maint_date', current)
114acco.getContent().edit(mapping=ds)
115wftool.doActionFor(acco,'pay_maintenance_fee',dest_container=acco)
116return context.REQUEST.RESPONSE.redirect("%s/accommodation_view" % student.absolute_url())
117
Note: See TracBrowser for help on using the repository browser.