source: waeup_product/trunk/skins/waeup_student/book_accommodation.py @ 124

Last change on this file since 124 was 124, checked in by Henrik Bettermann, 19 years ago

bug fixes

  • Property svn:keywords set to Id
File size: 2.2 KB
Line 
1##parameters=REQUEST
2# $Id: book_accommodation.py 124 2005-10-29 10:45:10Z henrik $
3"""
4book an accomodation
5"""
6type_name = 'Student'
7ti = context.portal_types[type_name]
8pm = context.portal_membership
9REQUEST.set('type_name',type_name)
10
11validate = REQUEST.has_key("cpsdocument_edit_button")
12
13
14lt = context.portal_layouts
15pr = context.portal_registration
16
17res,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                      )
24if psm == 'invalid':
25    return context.check_admission_form(rendered = res,
26                                 psm = "Please correct your input",
27                                 ds = ds,
28                                 )
29elif psm == '':
30    return context.check_admission_form(rendered = res,
31                                 psm = None,
32                                 ds = ds,
33                                 )
34elif 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)
Note: See TracBrowser for help on using the repository browser.