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

Last change on this file since 1128 was 1100, checked in by joachim, 18 years ago

reserve accommodation respects ekenhuan campus

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