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

Last change on this file since 1468 was 1412, checked in by joachim, 18 years ago

more documentation

M profiles/default/schemas/acco_hall.xml
M profiles/default/schemas/schema.xsl
M profiles/default/workflows/waeup_student_wf/definition.xml
M profiles/default/layouts/layout.xsl
M profiles/default/layouts/acco_bed_booking.xml
M profiles/default/layouts/acco_hall.xml
M profiles/default/types/Student.xml
M profiles/default/types/AccoFolder.xml
M profiles/default/types/AccoHall.xml
M doc/srp_documentation.mm

reserved bed functionallity,
pay hostel-fee for reserved bed

D skins/waeup_student/reserve_accommodation.py
M skins/waeup_accommodation/book_reserved_bed.py
A skins/waeup_accommodation/reserve_accommodation.py

  • Property svn:keywords set to Id
File size: 4.8 KB
Line 
1##parameters=REQUEST
2# $Id: reserve_accommodation.py 1412 2007-02-13 14:14:44Z joachim $
3"""
4process the the accommodation reservation
5"""
6import DateTime
7current = DateTime.DateTime()
8pr = context.portal_registration
9wftool = context.portal_workflow
10lt = context.portal_layouts
11info = context.getAccommodationInfo()
12
13import logging
14logger = logging.getLogger('Student.Accommodation.Reserve')
15
16#if info is None:
17#    return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
18
19if info is None:
20    member_id = str(context.portal_membership.getAuthenticatedMember())
21    logger.info('"%s","tried to reserve accommodation"' % (member_id))
22    return context.REQUEST.RESPONSE.redirect("%s/srp_invalid_access" % context.portal_url())
23
24mode = 'create'
25if not info['booking_allowed']:
26    return context.REQUEST.RESPONSE.redirect("%s/no_booking_allowed" % info['student'].absolute_url())
27student = info['student']
28acco_id = info['acco_id']
29session = acco_id[-4:]
30validate = REQUEST.has_key("cpsdocument_create_button")
31if info.has_key('acco') and info['acco']:
32    validate = REQUEST.has_key("cpsdocument_edit_button")
33    if info['acco_review_state'] == "maintenance_fee_paid":
34        return context.REQUEST.RESPONSE.redirect("%s/accommodation_view" % info['acco'].absolute_url())
35    else:
36        mode = 'edit'
37d = {}
38button = "Book"
39if mode == 'edit':
40    d['acco_res_date'] = info['acco_doc'].acco_res_date
41    d['acco_res_sc_pin'] = info['acco_doc'].acco_res_sc_pin
42    d['student_status'] = info['acco_doc'].student_status
43    d['bed'] = info['acco_doc'].bed
44    d['session'] = info['acco_doc'].session
45    button = "Pay Maintainance Fee"
46res,psm,ds = lt.renderLayout(layout_id= 'student_accommodation_fe',
47                      schema_id= 'student_accommodation',
48                      context=context,
49                      mapping=validate and REQUEST,
50                      ob=d,
51                      layout_mode=mode,
52                      formaction = "reserve_accommodation",
53                      button = button
54                      )
55if psm == 'invalid' or info['error'] is not None:
56    member_id = str(context.portal_membership.getAuthenticatedMember())
57    logger.info('"%s", %s' % (member_id,info['error'] ))
58    if psm == 'invalid':
59        psm = "Please correct your input."
60    else:
61        psm = "Error in data, unable to reserve bed."
62    return context.accommodation_pin_edit_form(rendered = res,
63                                 psm = psm,
64                                 #psm = "%s, %s" % (psm,ds),
65                                 mode = mode,
66                                 ds = ds,
67                                 )
68elif psm == '':
69    return context.accommodation_pin_edit_form(rendered = res,
70                                 psm = None,
71                                 mode = mode,
72                                 ds = ds,
73                                 )
74elif psm == 'valid':
75    s_id = ds.get('s_id')
76    if mode == 'create':
77        pin = str(ds.get('acco_res_sc_pin'))
78        pa = context.portal_accommodation
79        already = pa(student=s_id)
80        if not already:
81            code,bed = pa.searchAndReserveBed(s_id,"%s" % (info['student_status']))
82            #code,bed = pa.searchAndReserveBed(s_id,"%s_%s" % (info['sex'],ds.get('student_status')))
83            if code == -1:
84                return context.accommodation_pin_edit_form(rendered = res,
85                                     psm = "%s" % bed,
86                                     mode = mode,
87                                     ds = ds,
88                                     )
89            elif code == -2:
90                return context.accommodation_pin_edit_form(rendered = res,
91                                     psm = "No bed available. Your category is already fully booked.",
92                                     mode = mode,
93                                     ds = ds,
94                                     )
95        else:
96            bed = already[0].bed
97        student.invokeFactory('StudentAccommodation',acco_id)
98        acco = getattr(student,acco_id)
99        acco_info = context.waeup_tool.getAccommodationInfo(bed)
100        ds.set('acco_maint_code', acco_info.get('maintenance_code'))
101        ds.set('acco_maint_fee', acco_info.get('maintenance_fee'))
102        ds.set('acco_res_date', current)
103        ds.set('bed', bed)
104        ds.set('session', session)
105        ds.set('student_status',info['student_status'])
106        acco.getContent().edit(mapping=ds)
107        #wftool.doActionFor(acco,'pay_maintenance_fee',dest_container=acco)
108        return context.REQUEST.RESPONSE.redirect("%s/reserve_accommodation" % student.absolute_url())
109pin = str(ds.get('acco_main_sc_pin'))
110pp = context.portal_pins
111acco = getattr(student,acco_id)
112ds.set('acco_maint_date', current)
113acco.getContent().edit(mapping=ds)
114wftool.doActionFor(acco,'pay_maintenance_fee',dest_container=acco)
115return context.REQUEST.RESPONSE.redirect("%s/accommodation_view" % student.absolute_url())
116
Note: See TracBrowser for help on using the repository browser.