source: WAeUP_SRP/trunk/skins/waeup_student/reserve_accommodation.py @ 1353

Last change on this file since 1353 was 1306, checked in by Henrik Bettermann, 18 years ago

iteration over non sequence fixed

  • Property svn:keywords set to Id
File size: 4.7 KB
RevLine 
[629]1##parameters=REQUEST
[805]2# $Id: reserve_accommodation.py 1306 2007-01-16 06:33:04Z henrik $
[629]3"""
[1100]4process the the accommodation reservation
[629]5"""
6import DateTime
7current = DateTime.DateTime()
8pr = context.portal_registration
[659]9wftool = context.portal_workflow
[629]10lt = context.portal_layouts
[1100]11info = context.getAccommodationInfo()
[1133]12
[1140]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
[1133]19if info is None:
[1140]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())
[1133]23
[1183]24mode = 'create'
25if not info['booking_allowed']:
26    return context.REQUEST.RESPONSE.redirect("%s/no_booking_allowed" % info['student'].absolute_url())
[639]27student = info['student']
[1100]28acco_id = info['acco_id']
29session = acco_id[-4:]
30validate = REQUEST.has_key("cpsdocument_create_button")
[742]31if info.has_key('acco') and info['acco']:
[821]32    validate = REQUEST.has_key("cpsdocument_edit_button")
[835]33    if info['acco_review_state'] == "maintenance_fee_paid":
[742]34        return context.REQUEST.RESPONSE.redirect("%s/accommodation_view" % info['acco'].absolute_url())
35    else:
36        mode = 'edit'
37d = {}
[833]38button = "Book"
[742]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
[821]42    d['student_status'] = info['acco_doc'].student_status
[742]43    d['bed'] = info['acco_doc'].bed
44    d['session'] = info['acco_doc'].session
[821]45    button = "Pay Maintainance Fee"
[742]46res,psm,ds = lt.renderLayout(layout_id= 'student_accommodation_fe',
[686]47                      schema_id= 'student_accommodation',
[629]48                      context=context,
49                      mapping=validate and REQUEST,
[742]50                      ob=d,
51                      layout_mode=mode,
[652]52                      formaction = "reserve_accommodation",
[821]53                      button = button
[629]54                      )
[1255]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':
[1293]59        psm = "Please correct your input."
[1255]60    else:
[1293]61        psm = "Error in data, unable to reserve bed."
[849]62    return context.accommodation_pin_edit_form(rendered = res,
[1292]63                                 psm = psm,
[701]64                                 #psm = "%s, %s" % (psm,ds),
[821]65                                 mode = mode,
[629]66                                 ds = ds,
67                                 )
68elif psm == '':
[849]69    return context.accommodation_pin_edit_form(rendered = res,
[629]70                                 psm = None,
[821]71                                 mode = mode,
[629]72                                 ds = ds,
73                                 )
74elif psm == 'valid':
75    s_id = ds.get('s_id')
[742]76    if mode == 'create':
77        pin = str(ds.get('acco_res_sc_pin'))
78        pa = context.portal_accommodation
[1100]79        code,bed = pa.searchAndReserveBed(s_id,"%s" % (info['student_status']))
80        #code,bed = pa.searchAndReserveBed(s_id,"%s_%s" % (info['sex'],ds.get('student_status')))
[1305]81        if code == -1:
[855]82            return context.accommodation_pin_edit_form(rendered = res,
[1305]83                                 psm = "%s" % bed,
[821]84                                 mode = mode,
[635]85                                 ds = ds,
86                                 )
[1306]87        elif code == -2:
[1305]88            return context.accommodation_pin_edit_form(rendered = res,
89                                 psm = "No bed available. Your category is already fully booked.",
90                                 mode = mode,
91                                 ds = ds,
[1306]92                                 )
[742]93        student.invokeFactory('StudentAccommodation',acco_id)
94        acco = getattr(student,acco_id)
[828]95        acco_info = context.waeup_tool.getAccommodationInfo(bed)
96        ds.set('acco_maint_code', acco_info.get('maintenance_code'))
97        ds.set('acco_maint_fee', acco_info.get('maintenance_fee'))
[742]98        ds.set('acco_res_date', current)
99        ds.set('bed', bed)
100        ds.set('session', session)
[1100]101        ds.set('student_status',info['student_status'])
[742]102        acco.getContent().edit(mapping=ds)
[744]103        #wftool.doActionFor(acco,'pay_maintenance_fee',dest_container=acco)
[856]104        return context.REQUEST.RESPONSE.redirect("%s/reserve_accommodation" % student.absolute_url())
[742]105pin = str(ds.get('acco_main_sc_pin'))
106pp = context.portal_pins
[639]107acco = getattr(student,acco_id)
[742]108ds.set('acco_maint_date', current)
[639]109acco.getContent().edit(mapping=ds)
[744]110wftool.doActionFor(acco,'pay_maintenance_fee',dest_container=acco)
[660]111return context.REQUEST.RESPONSE.redirect("%s/accommodation_view" % student.absolute_url())
[1292]112
Note: See TracBrowser for help on using the repository browser.