source: waeup_product/trunk/skins/waeup_student/register_level.py @ 144

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

=added register_level

  • Property svn:keywords set to Id
File size: 2.8 KB
Line 
1##parameters=REQUEST
2# $Id: register_level.py 142 2005-11-02 18:04:59Z joachim $
3"""
4book an accomodation
5"""
6type_name = 'StudyLevel'
7ti = context.portal_types[type_name]
8pm = context.portal_membership
9REQUEST.set('type_name',type_name)
10
11validate = REQUEST.has_key("cpsdocument_create_button")
12
13
14lt = context.portal_layouts
15pv = context.portal_vocabularies
16#pr = context.portal_registration
17
18res,psm,ds = lt.renderLayout(layout_id= 'study_level',
19                      schema_id= 'metadata',
20                      context=context,
21                      mapping=validate and REQUEST,
22                      ob={},
23                      layout_mode='create',
24                      create_action = 'register_level',
25                      )
26if psm == 'invalid':
27    return context.common_edit_form(rendered = res,
28                                 create = 1,
29                                 type_name = type_name,
30                                 psm = 'Not yet active',
31                                 #psm = 'Please correct your errors',
32                                 )
33elif psm == '':
34    return context.common_edit_form(rendered = res,
35                                 create = 1,
36                                 type_name = type_name,
37                                 psm = psm,
38                                 #psm = str(ds),
39                                 )
40   
41elif psm == 'valid':
42    psm = (ds)
43    oid = ds.get('Title')
44    return context.common_edit_form(rendered = res,
45                                 create = 1,
46                                 type_name = type_name,
47                                 psm = 'Not yet active',
48                                 #psm = 'Please correct your errors',
49                                 )
50   
51    halls = getattr(context,'accommodation').contentValues()
52    beds = []
53    student = context.PERSONAL.getContent()
54    sf = context.getContent()
55    for hall in halls:
56        h = hall.getContent()
57        ba = int(getattr(h,'beds_assigned',0))
58        bal = getattr(h,'beds_assigned_list',[])
59        nr_of_beds = int(h.nr_of_blocks) * int(h.nr_of_floors) * int(h.rooms_per_floor) * int(h.beds_per_room)
60        if h.which_sex == student.sex and nr_of_beds > len(bal):
61            break
62    dict = {'heading': h.heading,
63            'text': h.text,
64            'which_sex': h.which_sex,
65            'nr_of_blocks': h.nr_of_blocks,
66            'nr_of_floors': h.nr_of_floors,
67            'rooms_per_floor': h.rooms_per_floor,
68            'beds_per_room': h.beds_per_room,
69            'nr_of_free': nr_of_beds,
70            'beds_assigned': ba,
71             }
72    ba += 1
73    dict['beds_assigned'] = ba
74    bal.append(('%s:%d' % (pm.getAuthenticatedMember(),ba)))
75    dict['beds_assigned_list'] = bal
76    psm = "h:%(heading)s free:%(nr_of_free)s %(beds_assigned)s" % dict
77    sf.edit(mapping = ds)
78    h.edit(mapping = dict)
79    #psm = "Your not admitted"
80    return context.booked_accommodation(v=dict)
Note: See TracBrowser for help on using the repository browser.