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
Line 
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
15logger = logging.getLogger('Accommodation.BookReservedBed')
16
17mode = 'create'
18validate = REQUEST.has_key("cpsdocument_edit_button") and\
19           REQUEST.get("cpsdocument_edit_button").startswith('Reserve')
20d = {}
21rendered,psm,ds = lt.renderLayout(layout_id= 'acco_bed_booking',
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."
31    return context.book_reserved_bed_form(rendered = rendered,
32                                 psm = psm,
33                                 #psm = "%s, %s" % (psm,ds),
34                                 mode = mode,
35                                 formaction = "book_reserved_bed",
36                                 button = "Reserve Bed",
37                                 ds = ds,
38                                 )
39elif psm == '':
40    return context.book_reserved_bed_form(rendered = rendered,
41                                 psm = psm,
42                                 mode = mode,
43                                 formaction = "book_reserved_bed",
44                                 button = "Reserve Bed",
45                                 ds = ds,
46                                 )
47elif psm == 'valid':
48    pass
49#from Products.zdb import set_trace;set_trace()
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)
58res = acco_cat(bed = bid)
59psm = ''
60while True:
61    if not res:
62        psm = "No bed with id %s" % bid
63        break
64    bed_brain = res[0]
65    already = acco_cat(student=sid)
66    if already:
67        psm = "Student %s already reserved bed %s" % (sid, already[0].bed)
68        break
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 != '':
80    return context.book_reserved_bed_form(rendered = rendered,
81                                 psm = psm,
82                                 mode = mode,
83                                 ds = ds,
84                                 formaction = "book_reserved_bed",
85                                 button = "Reserve Bed",
86                                 )
87acco_cat.modifyRecord(bed = bid, student = sid)
88logger.info('"%s","booked reserved bed %s for","%s"' % (member,bid,sid))
89return context.book_reserved_bed_form(rendered = "",
90                                 psm = "Bed reserved for %s %s" % (sid,student.name),
91                                 mode = mode,
92                                 formaction = "book_reserved_bed",
93                                 button = "Next Reservation",
94                                 ds = ds,
95                                 )
96
Note: See TracBrowser for help on using the repository browser.