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 5792 2011-03-03 13:54:24Z 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 | code,bed = context.portal_accommodation.searchAndReserveBed(student_id,
|
---|
73 | "%s" % (info['student_status']),
|
---|
74 | random_order=True)
|
---|
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 |
|
---|
94 | hall_info = context.waeup_tool.getHallInfo(bed)
|
---|
95 | data={}
|
---|
96 | data['acco_res_sc_pin'] = str(ds.get('acco_res_sc_pin',''))
|
---|
97 | data['acco_maint_code'] = hall_info.get('maintenance_code')
|
---|
98 | data['acco_maint_fee'] = hall_info.get('maintenance_fee')
|
---|
99 | data['acco_res_date'] = current
|
---|
100 | data['bed'] = bed
|
---|
101 | data['session'] = session
|
---|
102 | data['student_status'] = info['student_status']
|
---|
103 | data['catkey'] =student_id + '|' + session
|
---|
104 | data['student_id'] = student_id
|
---|
105 | data['reservation_status'] = 'bed_reserved'
|
---|
106 |
|
---|
107 | #set_trace()
|
---|
108 | context.accommodation_catalog.addRecord(**data)
|
---|
109 |
|
---|
110 | return context.REQUEST.RESPONSE.redirect("%s/accommodations" % student.absolute_url())
|
---|
111 |
|
---|