1 | ##parameters=REQUEST |
---|
2 | # $Id: book_reserved_bed.py 1393 2007-02-05 21:42:08Z joachim $ |
---|
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') |
---|
16 | |
---|
17 | mode = 'create' |
---|
18 | validate = REQUEST.has_key("cpsdocument_edit_button") |
---|
19 | d = {} |
---|
20 | res,psm,ds = lt.renderLayout(layout_id= 'acco_bed_booking', |
---|
21 | schema_id= 'acco_bed_booking', |
---|
22 | context=context, |
---|
23 | mapping=validate and REQUEST, |
---|
24 | ob=d, |
---|
25 | layout_mode='edit', |
---|
26 | commit = False |
---|
27 | ) |
---|
28 | if psm == 'invalid': |
---|
29 | psm = "Please correct your input." |
---|
30 | return context.book_reserved_bed_form(rendered = res, |
---|
31 | psm = psm, |
---|
32 | #psm = "%s, %s" % (psm,ds), |
---|
33 | mode = mode, |
---|
34 | formaction = "book_reserved_bed", |
---|
35 | button = "reserve bed", |
---|
36 | ds = ds, |
---|
37 | ) |
---|
38 | elif psm == '': |
---|
39 | return context.book_reserved_bed_form(rendered = res, |
---|
40 | psm = psm, |
---|
41 | mode = mode, |
---|
42 | formaction = "book_reserved_bed", |
---|
43 | button = "reserve bed", |
---|
44 | ds = ds, |
---|
45 | ) |
---|
46 | elif psm == 'valid': |
---|
47 | pass |
---|
48 | hall_id = context.getId() |
---|
49 | doc = context.getContent() |
---|
50 | student = ds.get('student') |
---|
51 | sid = ds.get('student_id') |
---|
52 | br = ds.get('block_room') |
---|
53 | block = br[0] |
---|
54 | bl = ds.get('bed_letter') |
---|
55 | bid = "%s_%s_%s" % (hall_id,br,bl) |
---|
56 | res = acco_cat(bed = bed) |
---|
57 | psm = '' |
---|
58 | while True: |
---|
59 | if not res: |
---|
60 | psm = "No bed with id %s" % bid |
---|
61 | break |
---|
62 | bed_brain = res[0] |
---|
63 | if not bed_brain.bed_type.endswith("reserved"): |
---|
64 | psm = "Not a reserved bed %s" % bid |
---|
65 | break |
---|
66 | if bed_brain.student: |
---|
67 | psm = "Bed %s already reserved for %s" % (bid,bed_brain.student) |
---|
68 | break |
---|
69 | if student.sex and not block in doc.blocks_for_female: |
---|
70 | psm = "Sex does not match %s" % bid |
---|
71 | break |
---|
72 | break |
---|
73 | if psm != '': |
---|
74 | return context.book_reserved_bed_form(rendered = res, |
---|
75 | psm = psm, |
---|
76 | mode = mode, |
---|
77 | ds = ds, |
---|
78 | formaction = "book_reserved_bed", |
---|
79 | button = "reserve bed", |
---|
80 | ) |
---|
81 | acco_cat.modifyRecord(bed = bed, student = sid) |
---|
82 | logger.info('"%s","booked reserved bed %s for","%s"' % (member,bed,sid)) |
---|
83 | return context.book_reserved_bed_form(rendered = res, |
---|
84 | psm = "Bed reserved for %s %s" % (sid,student.name), |
---|
85 | mode = mode, |
---|
86 | formaction = "book_reserved_bed", |
---|
87 | button = "reserve bed", |
---|
88 | ds = ds, |
---|
89 | ) |
---|
90 | |
---|