Index: waeup_product/trunk/skins/waeup_student/register_level.py
===================================================================
--- waeup_product/trunk/skins/waeup_student/register_level.py	(revision 142)
+++ waeup_product/trunk/skins/waeup_student/register_level.py	(revision 142)
@@ -0,0 +1,80 @@
+##parameters=REQUEST
+# $Id$
+"""
+book an accomodation
+"""
+type_name = 'StudyLevel'
+ti = context.portal_types[type_name]
+pm = context.portal_membership
+REQUEST.set('type_name',type_name)
+
+validate = REQUEST.has_key("cpsdocument_create_button")
+
+
+lt = context.portal_layouts
+pv = context.portal_vocabularies
+#pr = context.portal_registration
+
+res,psm,ds = lt.renderLayout(layout_id= 'study_level',
+                      schema_id= 'metadata',
+                      context=context,
+                      mapping=validate and REQUEST,
+                      ob={},
+                      layout_mode='create',
+                      create_action = 'register_level',
+                      )
+if psm == 'invalid':
+    return context.common_edit_form(rendered = res,
+                                 create = 1,
+                                 type_name = type_name,
+                                 psm = 'Not yet active',
+                                 #psm = 'Please correct your errors',
+                                 )
+elif psm == '':
+    return context.common_edit_form(rendered = res,
+                                 create = 1,
+                                 type_name = type_name,
+                                 psm = psm,
+                                 #psm = str(ds),
+                                 )
+    
+elif psm == 'valid':
+    psm = (ds)
+    oid = ds.get('Title')
+    return context.common_edit_form(rendered = res,
+                                 create = 1,
+                                 type_name = type_name,
+                                 psm = 'Not yet active',
+                                 #psm = 'Please correct your errors',
+                                 )
+    
+    halls = getattr(context,'accommodation').contentValues()
+    beds = []
+    student = context.PERSONAL.getContent()
+    sf = context.getContent()
+    for hall in halls:
+        h = hall.getContent()
+        ba = int(getattr(h,'beds_assigned',0))
+        bal = getattr(h,'beds_assigned_list',[])
+        nr_of_beds = int(h.nr_of_blocks) * int(h.nr_of_floors) * int(h.rooms_per_floor) * int(h.beds_per_room)
+        if h.which_sex == student.sex and nr_of_beds > len(bal):
+            break
+    dict = {'heading': h.heading,
+            'text': h.text,
+            'which_sex': h.which_sex,
+            'nr_of_blocks': h.nr_of_blocks,
+            'nr_of_floors': h.nr_of_floors,
+            'rooms_per_floor': h.rooms_per_floor,
+            'beds_per_room': h.beds_per_room,
+            'nr_of_free': nr_of_beds,
+            'beds_assigned': ba,
+             }
+    ba += 1
+    dict['beds_assigned'] = ba
+    bal.append(('%s:%d' % (pm.getAuthenticatedMember(),ba)))
+    dict['beds_assigned_list'] = bal
+    psm = "h:%(heading)s free:%(nr_of_free)s %(beds_assigned)s" % dict
+    sf.edit(mapping = ds)
+    h.edit(mapping = dict)
+    #psm = "Your not admitted"
+    return context.booked_accommodation(v=dict)
