source: WAeUP_SRP/trunk/skins/waeup_fceokene/reserve_accommodation.py @ 8794

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

ease disabling hostel booking also for fceokene

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