1 | ##parameters=REQUEST |
---|
2 | # $Id: book_reserved_bed.py 1426 2007-02-15 20:59:20Z henrik $ |
---|
3 | """ |
---|
4 | process the the accommodation reservation |
---|
5 | """ |
---|
6 | import DateTime |
---|
7 | current = DateTime.DateTime() |
---|
8 | pr = context.portal_registration |
---|
9 | wftool = context.portal_workflow |
---|
10 | lt = context.portal_layouts |
---|
11 | mtool = context.portal_membership |
---|
12 | member = mtool.getAuthenticatedMember() |
---|
13 | acco_cat = context.portal_accommodation |
---|
14 | import logging |
---|
15 | logger = logging.getLogger('Accommodation.BookReservedBed') |
---|
16 | |
---|
17 | mode = 'create' |
---|
18 | validate = REQUEST.has_key("cpsdocument_edit_button") and\ |
---|
19 | REQUEST.get("cpsdocument_edit_button").startswith('Reserve') |
---|
20 | d = {} |
---|
21 | rendered,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 | ) |
---|
29 | if 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 | ) |
---|
39 | elif 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 | ) |
---|
47 | elif psm == 'valid': |
---|
48 | pass |
---|
49 | #from Products.zdb import set_trace;set_trace() |
---|
50 | hall_id = context.getId() |
---|
51 | doc = context.getContent() |
---|
52 | student = ds.get('student') |
---|
53 | sid = ds.get('student_id') |
---|
54 | br = ds.get('block_room') |
---|
55 | block = br[0] |
---|
56 | bl = ds.get('bed_letter') |
---|
57 | bid = "%s_%s_%s" % (hall_id,br,bl) |
---|
58 | res = acco_cat(bed = bid) |
---|
59 | psm = '' |
---|
60 | while 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 |
---|
79 | if 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 | ) |
---|
87 | acco_cat.modifyRecord(bed = bid, student = sid) |
---|
88 | logger.info('"%s","booked reserved bed %s for","%s"' % (member,bid,sid)) |
---|
89 | return 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 | |
---|