source: WAeUP_SRP/trunk/skins/waeup_accommodation/book_reserved_bed.py @ 1439

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

jamb_reg_no added

  • Property svn:keywords set to Id
File size: 3.5 KB
RevLine 
[1393]1##parameters=REQUEST
2# $Id: book_reserved_bed.py 1426 2007-02-15 20:59:20Z henrik $
3"""
4process the the accommodation reservation
5"""
6import DateTime
7current = DateTime.DateTime()
8pr = context.portal_registration
9wftool = context.portal_workflow
10lt = context.portal_layouts
11mtool = context.portal_membership
12member = mtool.getAuthenticatedMember()
13acco_cat = context.portal_accommodation
14import logging
[1426]15logger = logging.getLogger('Accommodation.BookReservedBed')
[1393]16
17mode = 'create'
[1412]18validate = REQUEST.has_key("cpsdocument_edit_button") and\
[1426]19           REQUEST.get("cpsdocument_edit_button").startswith('Reserve')
[1393]20d = {}
[1412]21rendered,psm,ds = lt.renderLayout(layout_id= 'acco_bed_booking',
[1393]22                      schema_id= 'acco_bed_booking',
23                      context=context,
24                      mapping=validate and REQUEST,
25                      ob=d,
26                      layout_mode='edit',
27                      commit = False
28                      )
29if psm == 'invalid':
30    psm = "Please correct your input."
[1412]31    return context.book_reserved_bed_form(rendered = rendered,
[1393]32                                 psm = psm,
33                                 #psm = "%s, %s" % (psm,ds),
34                                 mode = mode,
35                                 formaction = "book_reserved_bed",
[1426]36                                 button = "Reserve Bed",
[1393]37                                 ds = ds,
38                                 )
39elif psm == '':
[1412]40    return context.book_reserved_bed_form(rendered = rendered,
[1393]41                                 psm = psm,
42                                 mode = mode,
43                                 formaction = "book_reserved_bed",
[1426]44                                 button = "Reserve Bed",
[1393]45                                 ds = ds,
46                                 )
47elif psm == 'valid':
48    pass
[1412]49#from Products.zdb import set_trace;set_trace()
[1393]50hall_id = context.getId()
51doc = context.getContent()
52student = ds.get('student')
53sid = ds.get('student_id')
54br = ds.get('block_room')
55block = br[0]
56bl = ds.get('bed_letter')
57bid = "%s_%s_%s" % (hall_id,br,bl)
[1410]58res = acco_cat(bed = bid)
[1393]59psm = ''
60while True:
61    if not res:
62        psm = "No bed with id %s" % bid
63        break
64    bed_brain = res[0]
[1426]65    already = acco_cat(student=sid)
[1412]66    if already:
67        psm = "Student %s already reserved bed %s" % (sid, already[0].bed)
68        break
[1393]69    if not bed_brain.bed_type.endswith("reserved"):
70        psm = "Not a reserved bed %s" % bid
71        break
72    if bed_brain.student:
73        psm = "Bed %s already reserved for %s" % (bid,bed_brain.student)
74        break
75    if student.sex and not block in doc.blocks_for_female:
76        psm = "Sex does not match %s" % bid
77        break
78    break
79if psm != '':
[1412]80    return context.book_reserved_bed_form(rendered = rendered,
[1393]81                                 psm = psm,
82                                 mode = mode,
83                                 ds = ds,
84                                 formaction = "book_reserved_bed",
[1426]85                                 button = "Reserve Bed",
[1393]86                                 )
[1410]87acco_cat.modifyRecord(bed = bid, student = sid)
[1412]88logger.info('"%s","booked reserved bed %s for","%s"' % (member,bid,sid))
89return context.book_reserved_bed_form(rendered = "",
[1393]90                                 psm = "Bed reserved for %s %s" % (sid,student.name),
91                                 mode = mode,
92                                 formaction = "book_reserved_bed",
[1426]93                                 button = "Next Reservation",
[1393]94                                 ds = ds,
95                                 )
96
Note: See TracBrowser for help on using the repository browser.