1 | ##parameters=REQUEST |
---|
2 | # $Id: book_accommodation.py 166 2005-11-12 14:45:08Z joachim $ |
---|
3 | """ |
---|
4 | book an accomodation |
---|
5 | """ |
---|
6 | import DateTime |
---|
7 | current = DateTime.DateTime() |
---|
8 | |
---|
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', |
---|
21 | schema_id= 'student_accommodation', |
---|
22 | context=context, |
---|
23 | mapping=validate and REQUEST, |
---|
24 | ob={}, |
---|
25 | layout_mode='create', |
---|
26 | submit = "book", |
---|
27 | action = 'book_accommodation', |
---|
28 | ) |
---|
29 | if psm == 'invalid': |
---|
30 | return context.book_accommodation_form(rendered = res, |
---|
31 | psm = "Please correct your input", |
---|
32 | ds = ds, |
---|
33 | ) |
---|
34 | elif psm == '': |
---|
35 | return context.book_accommodation_form(rendered = res, |
---|
36 | psm = None, |
---|
37 | ds = ds, |
---|
38 | ) |
---|
39 | elif psm == 'valid': |
---|
40 | sf = context.getContent() |
---|
41 | halls = getattr(context,'accommodation').contentValues() |
---|
42 | beds = [] |
---|
43 | student = context.PERSONAL.getContent() |
---|
44 | sf = context.getContent() |
---|
45 | for hall in halls: |
---|
46 | h = hall.getContent() |
---|
47 | ba = int(getattr(h,'beds_assigned',0)) |
---|
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) |
---|
50 | if h.which_sex == student.sex and nr_of_beds > len(bal): |
---|
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 |
---|
66 | h.edit(mapping = dict) |
---|
67 | ds.set('accommodation', "Bed # %(beds_assigned)s in %(heading)s" % dict) |
---|
68 | sf.edit(mapping = ds) |
---|
69 | #psm = "Your not admitted" |
---|
70 | psm = "h:%(heading)s free:%(nr_of_free)s %(beds_assigned)s" % dict |
---|
71 | |
---|
72 | ds.set('sc_date',current) |
---|
73 | sf.setScratchCardData('accommodation',ds) |
---|
74 | |
---|
75 | return context.booked_accommodation(v=dict) |
---|