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 5781 2011-02-28 10:53:12Z henrik $
|
---|
9 | """
|
---|
10 | process the the accommodation reservation
|
---|
11 | """
|
---|
12 | try:
|
---|
13 | from Products.zdb import set_trace
|
---|
14 | except:
|
---|
15 | def set_trace():
|
---|
16 | pass
|
---|
17 | import DateTime
|
---|
18 | current = DateTime.DateTime()
|
---|
19 | pr = context.portal_registration
|
---|
20 | wftool = context.portal_workflow
|
---|
21 | lt = context.portal_layouts
|
---|
22 | info = context.getAccommodationStatus()
|
---|
23 |
|
---|
24 | import logging
|
---|
25 | logger = logging.getLogger('Skins.book_accommodation')
|
---|
26 |
|
---|
27 | if 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 |
|
---|
32 | if info['booking_disabled']:
|
---|
33 | return context.REQUEST.RESPONSE.redirect("%s/booking_disabled" % info['student'].absolute_url())
|
---|
34 | if not info['booking_allowed']:
|
---|
35 | return context.REQUEST.RESPONSE.redirect("%s/no_booking_allowed" % info['student'].absolute_url())
|
---|
36 | student = info['student']
|
---|
37 | student_id = info['student_id']
|
---|
38 | acco_id = info['acco_id']
|
---|
39 | session = info['session'][0]
|
---|
40 | mode = 'create'
|
---|
41 | validate = REQUEST.has_key("cpsdocument_create_button")
|
---|
42 | button = 'Book'
|
---|
43 |
|
---|
44 | res,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 |
|
---|
55 | if 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 | )
|
---|
65 | elif psm == '':
|
---|
66 | return context.book_accommodation_form(rendered = res,
|
---|
67 | psm = None,
|
---|
68 | mode = mode,
|
---|
69 | ds = ds,
|
---|
70 | )
|
---|
71 | elif 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=True)
|
---|
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 |
|
---|
95 | hall_info = context.waeup_tool.getHallInfo(bed)
|
---|
96 | data={}
|
---|
97 | data['acco_res_sc_pin'] = ds['acco_res_sc_pin']
|
---|
98 | data['acco_maint_code'] = hall_info.get('maintenance_code')
|
---|
99 | data['acco_maint_fee'] = hall_info.get('maintenance_fee')
|
---|
100 | data['acco_res_date'] = current
|
---|
101 | data['bed'] = bed
|
---|
102 | data['session'] = session
|
---|
103 | data['student_status'] = info['student_status']
|
---|
104 | data['catkey'] =student_id + '|' + session
|
---|
105 | data['student_id'] = student_id
|
---|
106 | data['reservation_status'] = 'bed_reserved'
|
---|
107 |
|
---|
108 | #set_trace()
|
---|
109 | context.accommodation_catalog.addRecord(**data)
|
---|
110 |
|
---|
111 | return context.REQUEST.RESPONSE.redirect("%s/accommodations" % student.absolute_url())
|
---|
112 |
|
---|