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

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

Fix traceback.

  • Property svn:keywords set to Id
File size: 4.0 KB
Line 
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 5791 2011-03-03 13:53:34Z 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    code,bed = context.portal_accommodation.searchAndReserveBed(student_id,
73                                                                "%s" % (info['student_status']),
74                                                                random_order=False)
75    while True:
76        if code == 1:
77            break
78        if code == -1:
79            break
80        elif code == -2:
81            return context.book_accommodation_form(rendered = res,
82                                    psm = "No bed available. Your category is already fully booked.",
83                                    mode = mode,
84                                    ds = ds,
85                                    )
86        else: # unknown error
87            return context.book_accommodation_form(rendered = res,
88                                    psm = "Unexpected Error!",
89                                    mode = mode,
90                                    ds = ds,
91                                    )
92
93
94hall_info = context.waeup_tool.getHallInfo(bed)
95data={}
96data['acco_res_sc_pin'] = str(ds.get('acco_res_sc_pin',''))
97data['acco_maint_code'] = hall_info.get('maintenance_code')
98data['acco_maint_fee'] = hall_info.get('maintenance_fee')
99data['acco_res_date'] = current
100data['bed'] = bed
101data['session'] = session
102data['student_status'] = info['student_status']
103data['catkey'] =student_id + '|' + session
104data['student_id'] = student_id
105data['reservation_status'] = 'bed_reserved'
106
107#set_trace()
108context.accommodation_catalog.addRecord(**data)
109
110return context.REQUEST.RESPONSE.redirect("%s/accommodations" % student.absolute_url())
111
Note: See TracBrowser for help on using the repository browser.