[1393] | 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 |
---|
[1426] | 15 | logger = logging.getLogger('Accommodation.BookReservedBed') |
---|
[1393] | 16 | |
---|
| 17 | mode = 'create' |
---|
[1412] | 18 | validate = REQUEST.has_key("cpsdocument_edit_button") and\ |
---|
[1426] | 19 | REQUEST.get("cpsdocument_edit_button").startswith('Reserve') |
---|
[1393] | 20 | d = {} |
---|
[1412] | 21 | rendered,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 | ) |
---|
| 29 | if 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 | ) |
---|
| 39 | elif 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 | ) |
---|
| 47 | elif psm == 'valid': |
---|
| 48 | pass |
---|
[1412] | 49 | #from Products.zdb import set_trace;set_trace() |
---|
[1393] | 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) |
---|
[1410] | 58 | res = acco_cat(bed = bid) |
---|
[1393] | 59 | psm = '' |
---|
| 60 | while 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 |
---|
| 79 | if 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] | 87 | acco_cat.modifyRecord(bed = bid, student = sid) |
---|
[1412] | 88 | logger.info('"%s","booked reserved bed %s for","%s"' % (member,bid,sid)) |
---|
| 89 | return 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 | |
---|