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

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

reserve_accommodation only allowed for cleared_and_validated
several bugs fixed

  • Property svn:keywords set to Id
File size: 3.7 KB
RevLine 
[629]1##parameters=REQUEST
[805]2# $Id: reserve_accommodation.py 942 2006-11-25 21:09:18Z henrik $
[629]3"""
4process the Application Form
5return html renderer + psm
6"""
7import DateTime
8current = DateTime.DateTime()
9pr = context.portal_registration
[659]10wftool = context.portal_workflow
[629]11
[635]12info = context.getStudentInfo()
[821]13validate = REQUEST.has_key("cpsdocument_create_button")
14#           REQUEST.has_key("cpsdocument_edit_button")
[629]15
16lt = context.portal_layouts
17pr = context.portal_registration
[639]18session = current.year()
[659]19acco_id = 'accommodation_%s' % session
[639]20info = context.getStudentInfo()
21student = info['student']
[742]22mode = 'create'
[942]23
24if info['review_state'] != 'cleared_and_validated':
25    return context.REQUEST.RESPONSE.redirect("%s/no_booking_allowed" % info['student'].absolute_url())
26
[742]27if info.has_key('acco') and info['acco']:
[821]28    validate = REQUEST.has_key("cpsdocument_edit_button")
[835]29    if info['acco_review_state'] == "maintenance_fee_paid":
[742]30        return context.REQUEST.RESPONSE.redirect("%s/accommodation_view" % info['acco'].absolute_url())
31    else:
32        mode = 'edit'
33d = {}
[833]34button = "Book"
[742]35if mode == 'edit':
36    info = context.getStudentInfo()
37    d['acco_res_date'] = info['acco_doc'].acco_res_date
38    d['acco_res_sc_pin'] = info['acco_doc'].acco_res_sc_pin
[821]39    d['student_status'] = info['acco_doc'].student_status
[742]40    d['bed'] = info['acco_doc'].bed
41    d['session'] = info['acco_doc'].session
[821]42    button = "Pay Maintainance Fee"
[742]43res,psm,ds = lt.renderLayout(layout_id= 'student_accommodation_fe',
[686]44                      schema_id= 'student_accommodation',
[629]45                      context=context,
46                      mapping=validate and REQUEST,
[742]47                      ob=d,
48                      layout_mode=mode,
[652]49                      formaction = "reserve_accommodation",
[821]50                      button = button
[629]51                      )
52if psm == 'invalid':
[849]53    return context.accommodation_pin_edit_form(rendered = res,
[892]54                                 psm = "Please correct your input!",
[701]55                                 #psm = "%s, %s" % (psm,ds),
[821]56                                 mode = mode,
[629]57                                 ds = ds,
58                                 )
59elif psm == '':
[849]60    return context.accommodation_pin_edit_form(rendered = res,
[629]61                                 psm = None,
[821]62                                 mode = mode,
[629]63                                 ds = ds,
64                                 )
65elif psm == 'valid':
66    s_id = ds.get('s_id')
[742]67    if mode == 'create':
68        pin = str(ds.get('acco_res_sc_pin'))
69        pa = context.portal_accommodation
70        code,bed = pa.searchAndReserveBed(s_id,"%s_%s" % (info['sex'],ds.get('student_status')))
71        if code < 0:
[855]72            return context.accommodation_pin_edit_form(rendered = res,
[635]73                                 psm = bed,
[821]74                                 mode = mode,
[635]75                                 ds = ds,
76                                 )
[742]77        student.invokeFactory('StudentAccommodation',acco_id)
78        acco = getattr(student,acco_id)
[828]79        acco_info = context.waeup_tool.getAccommodationInfo(bed)
80        ds.set('acco_maint_code', acco_info.get('maintenance_code'))
81        ds.set('acco_maint_fee', acco_info.get('maintenance_fee'))
[742]82        ds.set('acco_res_date', current)
83        ds.set('bed', bed)
84        ds.set('session', session)
85        acco.getContent().edit(mapping=ds)
[744]86        #wftool.doActionFor(acco,'pay_maintenance_fee',dest_container=acco)
[856]87        return context.REQUEST.RESPONSE.redirect("%s/reserve_accommodation" % student.absolute_url())
[742]88pin = str(ds.get('acco_main_sc_pin'))
89pp = context.portal_pins
[639]90acco = getattr(student,acco_id)
[742]91ds.set('acco_maint_date', current)
[639]92acco.getContent().edit(mapping=ds)
[744]93wftool.doActionFor(acco,'pay_maintenance_fee',dest_container=acco)
[660]94return context.REQUEST.RESPONSE.redirect("%s/accommodation_view" % student.absolute_url())
Note: See TracBrowser for help on using the repository browser.