source: WAeUP_SRP/trunk/skins/waeup_accommodation/reserve_accommodation.py @ 5617

Last change on this file since 5617 was 4007, checked in by Henrik Bettermann, 16 years ago

ease disabling hostel booking (not yet tested)

FCE Okene remains unchanged.

File size: 6.4 KB
Line 
1## Script (Python) "reserve_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: reserve_accommodation.py 3406 2008-04-02 07:16:08Z 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.getAccommodationInfo()
23
24import logging
25logger = logging.getLogger('Skins.reserve_accommodation')
26
27#if info is None:
28#    return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
29
30if info is None:
31    member_id = str(context.portal_membership.getAuthenticatedMember())
32    logger.info('%s tried to reserve accommodation' % (member_id))
33    return context.REQUEST.RESPONSE.redirect("%s/srp_invalid_access" % context.portal_url())
34
35mode = 'create'
36if info['booking_disabled']:
37    return context.REQUEST.RESPONSE.redirect("%s/booking_disabled" % info['student'].absolute_url())
38if not info['booking_allowed']:
39    return context.REQUEST.RESPONSE.redirect("%s/no_booking_allowed" % info['student'].absolute_url())
40student = info['student']
41student_id = info['student_id']
42acco_id = info['acco_id']
43#session = info['session'][1]
44session = info['session'][0]
45
46validate = REQUEST.has_key("cpsdocument_create_button")
47if info.has_key('acco') and info['acco']:
48    validate = REQUEST.has_key("cpsdocument_edit_button")
49    if info['maintenance_paid']:
50        if not info['acco_doc'].acco_maint_fee:
51            d_update = {}
52            hall_info = context.waeup_tool.getHallInfo(info['acco_doc'].bed)
53            d_update['acco_maint_fee'] = hall_info.get('maintenance_fee')
54            wftool.doActionFor(info['acco'],'reserve_bed')
55            info['acco_doc'].edit(mapping=d_update)
56            wftool.doActionFor(info['acco'],'pay_maintenance_fee')
57        return context.REQUEST.RESPONSE.redirect("%s/accommodation_view" % info['acco'].absolute_url())
58    # elif info['online_payment']:
59    #     return context.REQUEST.RESPONSE.redirect("%s/accommodation_view" % info['acco'].absolute_url())
60    #     # return context.REQUEST.RESPONSE.redirect("%s/pay_interswitch_acco?paytype=HOM" % info['student'].absolute_url())
61    else:
62        mode = 'edit'
63d = {}
64button = "Book"
65if mode == 'edit':
66    d['acco_res_date'] = info['acco_doc'].acco_res_date
67    d['acco_res_sc_pin'] = info['acco_doc'].acco_res_sc_pin
68    d['acco_maint_fee'] = info['acco_doc'].acco_maint_fee
69    d['student_status'] = info['acco_doc'].student_status
70    d['bed'] = info['acco_doc'].bed
71    d['session'] = info['acco_doc'].session
72    button = "Pay Maintainance Fee"
73res,psm,ds = lt.renderLayout(layout_id= 'student_accommodation_fe',
74                      schema_id= 'student_accommodation',
75                      context=context,
76                      mapping=validate and REQUEST,
77                      ob=d,
78                      layout_mode=mode,
79                      formaction = "reserve_accommodation",
80                      button = button
81                      )
82if psm == 'invalid':                      # or info['error'] is not None:
83    member_id = str(context.portal_membership.getAuthenticatedMember())
84    #logger.info('%s, %s' % (member_id,info['error'] ))
85    logger.info('%s entered invalid data' % (member_id))
86    if psm == 'invalid':
87        psm = "Please correct your input."
88    else:
89        psm = "Error in data, unable to reserve bed."
90    return context.accommodation_edit_form(rendered = res,
91                                 psm = psm,
92                                 #psm = "%s, %s" % (psm,ds),
93                                 mode = mode,
94                                 ds = ds,
95                                 )
96elif psm == '':
97    return context.accommodation_edit_form(rendered = res,
98                                 psm = None,
99                                 mode = mode,
100                                 ds = ds,
101                                 )
102elif psm == 'valid':
103    if mode == 'create':
104        #set_trace()
105        pin = str(ds.get('acco_res_sc_pin'))
106        code,bed = context.portal_accommodation.searchAndReserveBed(student_id,
107                                                                    "%s" % (info['student_status']))
108        while True:
109            if code == 1:
110                break
111            if code == -1:
112                break
113                #return context.accommodation_edit_form(rendered = res,
114                #                        psm = "%s" % bed,
115                #                        mode = mode,
116                #                        ds = ds,
117                #                        )
118            elif code == -2:
119                return context.accommodation_edit_form(rendered = res,
120                                        psm = "No bed available. Your category is already fully booked.",
121                                        mode = mode,
122                                        ds = ds,
123                                        )
124            else: # unknown error
125                return context.accommodation_edit_form(rendered = res,
126                                        psm = "Unexpected Error!",
127                                        mode = mode,
128                                        ds = ds,
129                                        )
130        student.invokeFactory('StudentAccommodation',acco_id)
131        hall_info = context.waeup_tool.getHallInfo(bed)
132        ds.set('acco_maint_code', hall_info.get('maintenance_code'))
133        ds.set('acco_maint_fee', hall_info.get('maintenance_fee'))
134        ds.set('acco_res_date', current)
135        ds.set('bed', bed)
136        ds.set('session', session)
137        ds.set('student_status',info['student_status'])
138        acco = getattr(student,acco_id)
139        acco.getContent().edit(mapping=ds)
140        #wftool.doActionFor(acco,'pay_maintenance_fee',dest_container=acco)
141        return context.REQUEST.RESPONSE.redirect("%s/reserve_accommodation" % student.absolute_url())
142#pin = str(ds.get('acco_main_sc_pin'))
143#pp = context.portal_pins
144#acco = getattr(student,acco_id)
145d = {}
146d['acco_maint_sc_pin'] = ds.get('acco_maint_sc_pin')
147d['acco_maint_date'] = current
148info['acco_doc'].edit(mapping=d)
149wftool.doActionFor(info['acco'],'pay_maintenance_fee')
150return context.REQUEST.RESPONSE.redirect("%s/accommodation_view" % student.absolute_url())
151
Note: See TracBrowser for help on using the repository browser.