[114] | 1 | ##parameters=REQUEST |
---|
| 2 | # $Id: book_accommodation.py 404 2006-08-22 21:45:50Z joachim $ |
---|
| 3 | """ |
---|
[404] | 4 | book an accoMmodation |
---|
[114] | 5 | """ |
---|
[166] | 6 | import DateTime |
---|
| 7 | current = DateTime.DateTime() |
---|
| 8 | |
---|
[114] | 9 | type_name = 'Student' |
---|
| 10 | ti = context.portal_types[type_name] |
---|
| 11 | pm = context.portal_membership |
---|
| 12 | REQUEST.set('type_name',type_name) |
---|
| 13 | |
---|
| 14 | validate = REQUEST.has_key("cpsdocument_edit_button") |
---|
| 15 | |
---|
| 16 | |
---|
| 17 | lt = context.portal_layouts |
---|
| 18 | pr = context.portal_registration |
---|
| 19 | |
---|
| 20 | res,psm,ds = lt.renderLayout(layout_id= 'accobook', |
---|
[166] | 21 | schema_id= 'student_accommodation', |
---|
[114] | 22 | context=context, |
---|
| 23 | mapping=validate and REQUEST, |
---|
| 24 | ob={}, |
---|
| 25 | layout_mode='create', |
---|
[166] | 26 | submit = "book", |
---|
| 27 | action = 'book_accommodation', |
---|
[114] | 28 | ) |
---|
| 29 | if psm == 'invalid': |
---|
[164] | 30 | return context.book_accommodation_form(rendered = res, |
---|
[114] | 31 | psm = "Please correct your input", |
---|
| 32 | ds = ds, |
---|
| 33 | ) |
---|
| 34 | elif psm == '': |
---|
[164] | 35 | return context.book_accommodation_form(rendered = res, |
---|
[114] | 36 | psm = None, |
---|
| 37 | ds = ds, |
---|
| 38 | ) |
---|
| 39 | elif psm == 'valid': |
---|
| 40 | sf = context.getContent() |
---|
[124] | 41 | halls = getattr(context,'accommodation').contentValues() |
---|
[114] | 42 | beds = [] |
---|
[164] | 43 | student = context.PERSONAL.getContent() |
---|
[114] | 44 | sf = context.getContent() |
---|
| 45 | for hall in halls: |
---|
| 46 | h = hall.getContent() |
---|
[118] | 47 | ba = int(getattr(h,'beds_assigned',0)) |
---|
[114] | 48 | bal = getattr(h,'beds_assigned_list',[]) |
---|
| 49 | nr_of_beds = int(h.nr_of_blocks) * int(h.nr_of_floors) * int(h.rooms_per_floor) * int(h.beds_per_room) |
---|
[124] | 50 | if h.which_sex == student.sex and nr_of_beds > len(bal): |
---|
[114] | 51 | break |
---|
| 52 | dict = {'heading': h.heading, |
---|
| 53 | 'text': h.text, |
---|
| 54 | 'which_sex': h.which_sex, |
---|
| 55 | 'nr_of_blocks': h.nr_of_blocks, |
---|
| 56 | 'nr_of_floors': h.nr_of_floors, |
---|
| 57 | 'rooms_per_floor': h.rooms_per_floor, |
---|
| 58 | 'beds_per_room': h.beds_per_room, |
---|
| 59 | 'nr_of_free': nr_of_beds, |
---|
| 60 | 'beds_assigned': ba, |
---|
| 61 | } |
---|
| 62 | ba += 1 |
---|
| 63 | dict['beds_assigned'] = ba |
---|
| 64 | bal.append(('%s:%d' % (pm.getAuthenticatedMember(),ba))) |
---|
| 65 | dict['beds_assigned_list'] = bal |
---|
[163] | 66 | h.edit(mapping = dict) |
---|
| 67 | ds.set('accommodation', "Bed # %(beds_assigned)s in %(heading)s" % dict) |
---|
[114] | 68 | sf.edit(mapping = ds) |
---|
| 69 | #psm = "Your not admitted" |
---|
[163] | 70 | psm = "h:%(heading)s free:%(nr_of_free)s %(beds_assigned)s" % dict |
---|
[166] | 71 | |
---|
| 72 | ds.set('sc_date',current) |
---|
| 73 | sf.setScratchCardData('accommodation',ds) |
---|
| 74 | |
---|
[114] | 75 | return context.booked_accommodation(v=dict) |
---|