[1393] | 1 | ##parameters=REQUEST |
---|
| 2 | # $Id: book_reserved_bed.py 1440 2007-02-19 15:06:06Z 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 |
---|
[1426] | 15 | logger = logging.getLogger('Accommodation.BookReservedBed') |
---|
[1393] | 16 | |
---|
[1440] | 17 | change_bed = REQUEST.has_key("reserve_and_change") |
---|
| 18 | validate = change_bed or (REQUEST.has_key("reserve") and |
---|
| 19 | REQUEST.get("reserve").startswith('Reserve')) |
---|
[1393] | 20 | mode = 'create' |
---|
[1440] | 21 | |
---|
[1393] | 22 | d = {} |
---|
[1412] | 23 | rendered,psm,ds = lt.renderLayout(layout_id= 'acco_bed_booking', |
---|
[1393] | 24 | schema_id= 'acco_bed_booking', |
---|
| 25 | context=context, |
---|
| 26 | mapping=validate and REQUEST, |
---|
| 27 | ob=d, |
---|
| 28 | layout_mode='edit', |
---|
| 29 | commit = False |
---|
| 30 | ) |
---|
| 31 | if psm == 'invalid': |
---|
| 32 | psm = "Please correct your input." |
---|
[1412] | 33 | return context.book_reserved_bed_form(rendered = rendered, |
---|
[1393] | 34 | psm = psm, |
---|
| 35 | #psm = "%s, %s" % (psm,ds), |
---|
| 36 | mode = mode, |
---|
| 37 | formaction = "book_reserved_bed", |
---|
[1426] | 38 | button = "Reserve Bed", |
---|
[1393] | 39 | ds = ds, |
---|
| 40 | ) |
---|
| 41 | elif psm == '': |
---|
[1412] | 42 | return context.book_reserved_bed_form(rendered = rendered, |
---|
[1393] | 43 | psm = psm, |
---|
| 44 | mode = mode, |
---|
| 45 | formaction = "book_reserved_bed", |
---|
[1426] | 46 | button = "Reserve Bed", |
---|
[1393] | 47 | ds = ds, |
---|
| 48 | ) |
---|
| 49 | elif psm == 'valid': |
---|
| 50 | pass |
---|
[1412] | 51 | #from Products.zdb import set_trace;set_trace() |
---|
[1393] | 52 | hall_id = context.getId() |
---|
| 53 | doc = context.getContent() |
---|
| 54 | student = ds.get('student') |
---|
| 55 | sid = ds.get('student_id') |
---|
| 56 | br = ds.get('block_room') |
---|
| 57 | block = br[0] |
---|
| 58 | bl = ds.get('bed_letter') |
---|
| 59 | bid = "%s_%s_%s" % (hall_id,br,bl) |
---|
[1410] | 60 | res = acco_cat(bed = bid) |
---|
[1393] | 61 | psm = '' |
---|
| 62 | while True: |
---|
| 63 | if not res: |
---|
| 64 | psm = "No bed with id %s" % bid |
---|
| 65 | break |
---|
| 66 | bed_brain = res[0] |
---|
[1426] | 67 | already = acco_cat(student=sid) |
---|
[1440] | 68 | if already and not change_bed: |
---|
[1412] | 69 | psm = "Student %s already reserved bed %s" % (sid, already[0].bed) |
---|
| 70 | break |
---|
[1393] | 71 | if not bed_brain.bed_type.endswith("reserved"): |
---|
| 72 | psm = "Not a reserved bed %s" % bid |
---|
| 73 | break |
---|
[1440] | 74 | if bed_brain.student and not change_bed: |
---|
[1393] | 75 | psm = "Bed %s already reserved for %s" % (bid,bed_brain.student) |
---|
| 76 | break |
---|
| 77 | if student.sex and not block in doc.blocks_for_female: |
---|
| 78 | psm = "Sex does not match %s" % bid |
---|
| 79 | break |
---|
| 80 | break |
---|
| 81 | if psm != '': |
---|
[1412] | 82 | return context.book_reserved_bed_form(rendered = rendered, |
---|
[1393] | 83 | psm = psm, |
---|
| 84 | mode = mode, |
---|
| 85 | ds = ds, |
---|
| 86 | formaction = "book_reserved_bed", |
---|
[1426] | 87 | button = "Reserve Bed", |
---|
[1393] | 88 | ) |
---|
[1440] | 89 | if change_bed: |
---|
| 90 | for bed in already: |
---|
| 91 | acco_cat.modifyRecord(bed=bed.bed,student='') |
---|
| 92 | |
---|
[1410] | 93 | acco_cat.modifyRecord(bed = bid, student = sid) |
---|
[1440] | 94 | students = context.portal_url.getPortalObject().campus.students |
---|
| 95 | student_obj = getattr(students,sid) |
---|
| 96 | acco_id = "accommodation_%s" % context.getSessionId() |
---|
| 97 | if acco_id in student_obj.objectIds(): |
---|
| 98 | acco_doc = getattr(student_obj, acco_id).getContent() |
---|
| 99 | acco_doc.edit(mapping={'bed': bid}) |
---|
[1412] | 100 | logger.info('"%s","booked reserved bed %s for","%s"' % (member,bid,sid)) |
---|
[1440] | 101 | mode = 'view' |
---|
[1412] | 102 | return context.book_reserved_bed_form(rendered = "", |
---|
[1393] | 103 | psm = "Bed reserved for %s %s" % (sid,student.name), |
---|
| 104 | mode = mode, |
---|
| 105 | formaction = "book_reserved_bed", |
---|
[1426] | 106 | button = "Next Reservation", |
---|
[1393] | 107 | ds = ds, |
---|
| 108 | ) |
---|
| 109 | |
---|