source: WAeUP_SRP/trunk/skins/waeup_accommodation/book_accommodation.py @ 5755

Last change on this file since 5755 was 5616, checked in by Henrik Bettermann, 14 years ago

Implement second part of new accommodation allocation module. This part contains the new scripts and page templates needed. See ReadMe?.txt for further instructions.

  • Property svn:keywords set to Id
File size: 4.1 KB
RevLine 
[5616]1## Script (Python) "book_accommodation.py"
2##bind container=container
3##bind context=context
4##bind namespace=
5##bind script=script
6##bind subpath=traverse_subpath
7##parameters=REQUEST
8# $Id: book_accommodation.py 5616 2010-12-27 10:18:18Z henrik $
9"""
10process the the accommodation reservation
11"""
12try:
13    from Products.zdb import set_trace
14except:
15    def set_trace():
16        pass
17import DateTime
18current = DateTime.DateTime()
19pr = context.portal_registration
20wftool = context.portal_workflow
21lt = context.portal_layouts
22info = context.getAccommodationStatus()
23
24import logging
25logger = logging.getLogger('Skins.book_accommodation')
26
27if info is None:
28    member_id = str(context.portal_membership.getAuthenticatedMember())
29    logger.info('%s tried to reserve accommodation' % (member_id))
30    return context.REQUEST.RESPONSE.redirect("%s/srp_invalid_access" % context.portal_url())
31
32if info['booking_disabled']:
33    return context.REQUEST.RESPONSE.redirect("%s/booking_disabled" % info['student'].absolute_url())
34if not info['booking_allowed']:
35    return context.REQUEST.RESPONSE.redirect("%s/no_booking_allowed" % info['student'].absolute_url())
36student = info['student']
37student_id = info['student_id']
38acco_id = info['acco_id']
39session = info['session'][0]
40mode = 'create'
41validate = REQUEST.has_key("cpsdocument_create_button")
42button = 'Book'
43
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=info,
49                      layout_mode=mode,
50                      formaction = "book_accommodation",
51                      button = button)
52
53
54
55if psm == 'invalid':
56    member_id = str(context.portal_membership.getAuthenticatedMember())
57    #logger.info('%s, %s' % (member_id,info['error'] ))
58    logger.info('%s entered invalid data' % (member_id))
59    psm = "Please correct your input."
60    return context.book_accommodation_form(rendered = res,
61                                 psm = psm,
62                                 mode = mode,
63                                 ds = ds,
64                                 )
65elif psm == '':
66    return context.book_accommodation_form(rendered = res,
67                                 psm = None,
68                                 mode = mode,
69                                 ds = ds,
70                                 )
71elif psm == 'valid':
72    pin = str(ds.get('acco_res_sc_pin'))
73    code,bed = context.portal_accommodation.searchAndReserveBed(student_id,
74                                                                "%s" % (info['student_status']),
75                                                                random_order=False)
76    while True:
77        if code == 1:
78            break
79        if code == -1:
80            break
81        elif code == -2:
82            return context.book_accommodation_form(rendered = res,
83                                    psm = "No bed available. Your category is already fully booked.",
84                                    mode = mode,
85                                    ds = ds,
86                                    )
87        else: # unknown error
88            return context.book_accommodation_form(rendered = res,
89                                    psm = "Unexpected Error!",
90                                    mode = mode,
91                                    ds = ds,
92                                    )
93
94
95hall_info = context.waeup_tool.getHallInfo(bed)
96data={}
97data['acco_res_sc_pin'] = ds['acco_res_sc_pin']
98data['acco_maint_code'] = hall_info.get('maintenance_code')
99data['acco_maint_fee'] = hall_info.get('maintenance_fee')
100data['acco_res_date'] = current
101data['bed'] = bed
102data['session'] = session
103data['student_status'] = info['student_status']
104data['catkey'] =student_id + '|' + session
105data['student_id'] = student_id
106data['reservation_status'] = 'bed_reserved'
107
108#set_trace()
109context.accommodation_catalog.addRecord(**data)
110
111return context.REQUEST.RESPONSE.redirect("%s/accommodations" % student.absolute_url())
112
Note: See TracBrowser for help on using the repository browser.