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

Last change on this file since 164 was 164, checked in by joachim, 19 years ago

=clearence + eligibility added

  • Property svn:keywords set to Id
File size: 2.3 KB
Line 
1##parameters=REQUEST
2# $Id: book_accommodation.py 164 2005-11-10 21:40:01Z joachim $
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                      create_action = 'book_accommodation',
24                      )
25if psm == 'invalid':
26    return context.book_accommodation_form(rendered = res,
27                                 psm = "Please correct your input",
28                                 ds = ds,
29                                 )
30elif psm == '':
31    return context.book_accommodation_form(rendered = res,
32                                 psm = None,
33                                 ds = ds,
34                                 )
35elif psm == 'valid':
36    sf = context.getContent()
37    halls = getattr(context,'accommodation').contentValues()
38    beds = []
39    student = context.PERSONAL.getContent()
40    sf = context.getContent()
41    for hall in halls:
42        h = hall.getContent()
43        ba = int(getattr(h,'beds_assigned',0))
44        bal = getattr(h,'beds_assigned_list',[])
45        nr_of_beds = int(h.nr_of_blocks) * int(h.nr_of_floors) * int(h.rooms_per_floor) * int(h.beds_per_room)
46        if h.which_sex == student.sex and nr_of_beds > len(bal):
47            break
48    dict = {'heading': h.heading,
49            'text': h.text,
50            'which_sex': h.which_sex,
51            'nr_of_blocks': h.nr_of_blocks,
52            'nr_of_floors': h.nr_of_floors,
53            'rooms_per_floor': h.rooms_per_floor,
54            'beds_per_room': h.beds_per_room,
55            'nr_of_free': nr_of_beds,
56            'beds_assigned': ba,
57             }
58    ba += 1
59    dict['beds_assigned'] = ba
60    bal.append(('%s:%d' % (pm.getAuthenticatedMember(),ba)))
61    dict['beds_assigned_list'] = bal
62    h.edit(mapping = dict)
63    ds.set('accommodation', "Bed # %(beds_assigned)s in %(heading)s" % dict)
64    sf.edit(mapping = ds)
65    #psm = "Your not admitted"
66    psm = "h:%(heading)s free:%(nr_of_free)s %(beds_assigned)s" % dict
67    return context.booked_accommodation(v=dict)
Note: See TracBrowser for help on using the repository browser.