Index: main/waeup.sirp/trunk/src/waeup/sirp/hostels/browser.py
===================================================================
--- main/waeup.sirp/trunk/src/waeup/sirp/hostels/browser.py	(revision 6985)
+++ main/waeup.sirp/trunk/src/waeup/sirp/hostels/browser.py	(revision 6988)
@@ -223,7 +223,9 @@
     @grok.action('Update all beds')
     def updateBeds(self, **data):
-        removed, added, modified = self.context.updateBeds()
-        self.flash('%d empty beds removed, %d beds added, %d occupied beds modified' % (
-            removed, added, modified))
+        removed, added, modified, modified_beds = self.context.updateBeds()
+        message = '%d empty beds removed, %d beds added, %d occupied beds modified (%s)' % (
+            removed, added, modified, modified_beds)
+        self.flash(message)
+        write_log_message(self, message)
         self.redirect(self.url(self.context, '@@manage')+'#tab-2')
         return
@@ -243,6 +245,6 @@
         for bed_id in child_id:
             try:
-                self.context[bed_id].switchReservation()
-                switched.append(bed_id)
+                message = self.context[bed_id].switchReservation()
+                switched.append('%s (%s)' % (bed_id,message))
             except:
                 self.flash('Could not switch %s: %s: %s' % (
@@ -251,11 +253,14 @@
                 return
         if len(switched):
-            self.flash('Successfully switched beds: %s' % ', '.join(switched))
+            message = ', '.join(switched)
+            self.flash('Successfully switched beds: %s' % message)
+            write_log_message(self, 'switched: % s' % message)
             self.redirect(self.url(self.context, '@@manage')+'#tab-2')
         return
 
-    @grok.action('Release selected beds')
-    def releaseBeds(self, **data):
-        #self.flash('%d released' % released)
-        self.redirect(self.url(self.context, '@@manage')+'#tab-2')
-        return
+    # Needed for removing students from beds
+    #@grok.action('Release selected beds')
+    #def releaseBeds(self, **data):
+    #    #self.flash('%d released' % released)
+    #    self.redirect(self.url(self.context, '@@manage')+'#tab-2')
+    #    return
Index: main/waeup.sirp/trunk/src/waeup/sirp/hostels/hostel.py
===================================================================
--- main/waeup.sirp/trunk/src/waeup/sirp/hostels/hostel.py	(revision 6985)
+++ main/waeup.sirp/trunk/src/waeup/sirp/hostels/hostel.py	(revision 6988)
@@ -50,4 +50,5 @@
         modified_counter = 0
         removed_counter = 0
+        modified_beds = u''
 
         # Remove all empty beds. Occupied beds remain in hostel!
@@ -96,4 +97,5 @@
                                 bed.bed_type = bt
                                 modified_counter += 1
+                                modified_beds += '%s ' % uid
                         else:
                             bed = Bed()
@@ -104,5 +106,5 @@
                             self.addBed(bed)
                             added_counter +=1
-        return removed_counter, added_counter, modified_counter
+        return removed_counter, added_counter, modified_counter, modified_beds
 
 Hostel = attrs_to_fields(Hostel)
@@ -120,13 +122,13 @@
 
     def switchReservation(self):
-        """Reserves a bed or relases a reserved bed respectively.
+        """Reserves a bed or unreserve bed respectively.
         """
         sh, sex, bt = self.bed_type.split('_')
         hostel_id, block, room_nr, bed = self.getBedCoordinates()
-        beds_for_fresh = getattr(self,'beds_for_fresh',[])
-        beds_for_pre = getattr(self,'beds_for_pre',[])
-        beds_for_returning = getattr(self,'beds_for_returning',[])
-        beds_for_final = getattr(self,'beds_for_final',[])
         hostel = self.__parent__
+        beds_for_fresh = getattr(hostel,'beds_for_fresh',[])
+        beds_for_pre = getattr(hostel,'beds_for_pre',[])
+        beds_for_returning = getattr(hostel,'beds_for_returning',[])
+        beds_for_final = getattr(hostel,'beds_for_final',[])
         bed_string = u'%s_%s_%s' % (block, room_nr, bed)
         if bt == 'reserved':
@@ -142,9 +144,12 @@
             bt = u'%s_%s_%s' % (sh, sex, bt)
             hostel.beds_reserved.remove(bed_string)
+            message = u'unreserved'
         else:
             bt = u'%s_%s_reserved' % (sh, sex)
             hostel.beds_reserved.append(bed_string)
+            hostel._p_changed = True
+            message = u'reserved'
         self.bed_type = bt
-        return
+        return message
 
     def loggerInfo(self, ob_class, comment=None):
Index: main/waeup.sirp/trunk/src/waeup/sirp/hostels/tests.py
===================================================================
--- main/waeup.sirp/trunk/src/waeup/sirp/hostels/tests.py	(revision 6985)
+++ main/waeup.sirp/trunk/src/waeup/sirp/hostels/tests.py	(revision 6988)
@@ -15,5 +15,5 @@
 ##
 """
-Tests for hostels. and their UI components
+Tests for hostels and their UI components.
 """
 import shutil
@@ -157,4 +157,7 @@
         self.assertEqual(self.browser.headers['Status'], '200 Ok')
         self.assertTrue('Hostel created' in self.browser.contents)
+        self.browser.open(self.container_path + '/addhostel')
+        self.browser.getControl("Create hostel").click()
+        self.assertTrue('The hostel already exists' in self.browser.contents)
         hall = self.app['hostels']['hall-1']
         hall.blocks_for_female = ['A','B']
@@ -172,45 +175,59 @@
         self.assertTrue(len(hall.blocks_for_female) == 0)
         hall.blocks_for_female = ['A','B']
-        hall.beds_for_fresh = ['A','B']
+        hall.beds_for_fresh = ['A']
+        hall.beds_for_returning = ['B']
+        hall.beds_for_final = ['C']
         hall.beds_for_all = ['D','E']
         self.browser.getControl("Update all beds").click()
-        expected = '...0 empty beds removed, 8 beds added, 0 occupied beds modified...'
+        expected = '...0 empty beds removed, 10 beds added, 0 occupied beds modified ()...'
         self.assertMatches(expected,self.browser.contents)
         cat = queryUtility(ICatalog, name='beds_catalog')
         results = cat.searchResults(
             bed_type=('regular_female_all', 'regular_female_all'))
-        #import pdb; pdb.set_trace()
         results = [x for x in results]
         assert len(results) == 4
-        # Set bed reserved
-        ctrl = self.browser.getControl(name='val_id')
+        # Reserve bed
+        self.browser.getControl("Switch reservation", index=0).click()
+        self.assertTrue('No item selected' in self.browser.contents)
+        ctrl = self.browser.getControl(name='val_id')
+        ctrl.getControl(value='hall-1_A_101_A').selected = True
+        ctrl.getControl(value='hall-1_A_101_B').selected = True
+        ctrl.getControl(value='hall-1_A_101_C').selected = True
         ctrl.getControl(value='hall-1_A_101_D').selected = True
         self.browser.getControl("Switch reservation", index=0).click()
-        self.assertTrue('Successfully switched beds: hall-1_A_101_D'
+        self.assertTrue('Successfully switched beds: hall-1_A_101_A (reserved)'
             in self.browser.contents)
-        assert self.app[
-            'hostels'][
-            'hall-1'][
+        assert self.app['hostels']['hall-1'][
             'hall-1_A_101_D'].bed_type == 'regular_female_reserved'
-        expected = 'name="form.beds_reserved.0." size="20" type="text" value="A_101_D"  />'
+        expected = 'name="form.beds_reserved.0." size="20" type="text" value="A_101_A"  />'
         self.assertTrue(expected in self.browser.contents)
-        # Release bed
+        # Provoke exception
+        self.app['hostels']['hall-1']['hall-1_A_101_D'].bed_type = u'nonsense'
         ctrl = self.browser.getControl(name='val_id')
         ctrl.getControl(value='hall-1_A_101_D').selected = True
         self.browser.getControl("Switch reservation", index=0).click()
-        assert self.app[
-            'hostels'][
-            'hall-1'][
-            'hall-1_A_101_D'].bed_type == 'regular_female_all'
-        self.assertFalse(expected in self.browser.contents)
+        self.assertMatches(
+            '...need more than 1 value to unpack...', self.browser.contents)
+        self.app['hostels']['hall-1'][
+            'hall-1_A_101_D'].bed_type = u'regular_female_reserved'
         # Change hostel configuration
         hall.beds_for_all = ['D']
         self.browser.getControl("Update all beds").click()
-        expected = '...8 empty beds removed, 6 beds added, 0 occupied beds modified...'
+        expected = '...10 empty beds removed, 8 beds added, 0 occupied beds modified...'
         self.assertMatches(expected,self.browser.contents)
         results = cat.searchResults(
             bed_type=('regular_female_all', 'regular_female_all'))
         results = [x for x in results]
-        assert len(results) == 2
+        assert len(results) == 1
+        # Unreserve bed
+        ctrl = self.browser.getControl(name='val_id')
+        ctrl.getControl(value='hall-1_A_101_A').selected = True
+        ctrl.getControl(value='hall-1_A_101_B').selected = True
+        ctrl.getControl(value='hall-1_A_101_C').selected = True
+        ctrl.getControl(value='hall-1_A_101_D').selected = True
+        self.browser.getControl("Switch reservation", index=0).click()
+        assert self.app['hostels']['hall-1'][
+            'hall-1_A_101_D'].bed_type == 'regular_female_all'
+        self.assertFalse(expected in self.browser.contents)
         # Remove entire hostel
         self.browser.open(self.manage_container_path)
