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