Index: /main/waeup.sirp/trunk/src/waeup/sirp/hostels/browser.py
===================================================================
--- /main/waeup.sirp/trunk/src/waeup/sirp/hostels/browser.py	(revision 7069)
+++ /main/waeup.sirp/trunk/src/waeup/sirp/hostels/browser.py	(revision 7070)
@@ -289,9 +289,13 @@
         for bed_id in child_id:
             message = self.context[bed_id].releaseBed()
-            released.append('%s (%s)' % (bed_id,message))
+            if message:
+                released.append('%s (%s)' % (bed_id,message))
         if len(released):
             message = ', '.join(released)
             self.flash('Successfully released beds: %s' % message)
             write_log_message(self, 'released: %s' % message)
+            self.redirect(self.url(self.context, '@@manage')+'#tab-2')
+        else:
+            self.flash('No allocated bed selected.')
             self.redirect(self.url(self.context, '@@manage')+'#tab-2')
         return
Index: /main/waeup.sirp/trunk/src/waeup/sirp/hostels/container.py
===================================================================
--- /main/waeup.sirp/trunk/src/waeup/sirp/hostels/container.py	(revision 7069)
+++ /main/waeup.sirp/trunk/src/waeup/sirp/hostels/container.py	(revision 7070)
@@ -55,8 +55,5 @@
         """
         user = get_current_principal()
-        if user is None:
-            user = 'system'
-        else:
-            user = user.id
+        user = user.id
         self.logger.info('%s - %s - %s - %s' % (
                 user, ob_class, target, comment))
Index: /main/waeup.sirp/trunk/src/waeup/sirp/hostels/hostel.py
===================================================================
--- /main/waeup.sirp/trunk/src/waeup/sirp/hostels/hostel.py	(revision 7069)
+++ /main/waeup.sirp/trunk/src/waeup/sirp/hostels/hostel.py	(revision 7070)
@@ -178,5 +178,5 @@
     def releaseBed(self):
         if self.owner == NOT_OCCUPIED:
-            return u'not occupied'
+            return
         else:
             old_owner = self.owner
@@ -186,5 +186,4 @@
                 'configuration'].accommodation_session
             try:
-            #import pdb; pdb.set_trace()
                 bedticket = grok.getSite()['students'][old_owner][
                               'accommodation'][str(accommodation_session)]
Index: /main/waeup.sirp/trunk/src/waeup/sirp/hostels/tests.py
===================================================================
--- /main/waeup.sirp/trunk/src/waeup/sirp/hostels/tests.py	(revision 7069)
+++ /main/waeup.sirp/trunk/src/waeup/sirp/hostels/tests.py	(revision 7070)
@@ -283,4 +283,10 @@
         self.assertMatches(bedticket.bed_coordinates,
           u' -- booking cancelled on <YYYY-MM-DD hh:mm:ss> --')
+        # If we release a free be, nothing will happen
+        ctrl = self.browser.getControl(name='val_id')
+        ctrl.getControl(value='hall-1_A_101_D').selected = True
+        self.browser.getControl("Release selected beds", index=0).click()
+        self.assertMatches(
+          '...No allocated bed selected...', self.browser.contents)
         # Managers can manually allocate studenst after cancellation
         self.browser.open(self.container_path + '/hall-1/hall-1_A_101_A')
@@ -288,4 +294,33 @@
         self.browser.getControl("Save").click()
         self.assertMatches("...Form has been saved...", self.browser.contents)
+        # If we open the same form again, we will be redirected to hostel
+        # manage page. Beds must be released first before they can be
+        # allocated to other students.
+        self.browser.open(self.container_path + '/hall-1/hall-1_A_101_A')
+        self.assertEqual(self.browser.url,
+            self.container_path + '/hall-1/@@manage#tab-2')
+        # Updating the beds again will not affect the allocation and also
+        # the bed numbering remains the same
+        old_number = self.app['hostels']['hall-1']['hall-1_A_101_A'].bed_number
+        old_owner = self.app['hostels']['hall-1']['hall-1_A_101_A'].owner
+        self.browser.getControl("Update all beds").click()
+        # 7 beds have been removed and re-added, 1 bed remains untouched
+        expected = '...7 empty beds removed, 7 beds added, 0 occupied beds modified...'
+        self.assertMatches(expected,self.browser.contents)
+        new_number = self.app['hostels']['hall-1']['hall-1_A_101_A'].bed_number
+        new_owner = self.app['hostels']['hall-1']['hall-1_A_101_A'].owner
+        self.assertEqual(new_number, old_number)
+        self.assertEqual(new_owner, old_owner)
+        # If we change the bed type of an allocated bed, the modification will
+        # be indicated
+        hall.blocks_for_female = ['B']
+        hall.blocks_for_male = ['A']
+        self.browser.getControl("Update all beds").click()
+        expected = '...7 empty beds removed, 7 beds added, ' + \
+            '1 occupied beds modified (hall-1_A_101_A )...'
+        self.assertMatches(expected,self.browser.contents)
+        new_number = self.app['hostels']['hall-1']['hall-1_A_101_A'].bed_number
+        # Also the number of the bed has changed.
+        self.assertFalse(new_number == old_number)
         # Remove entire hostel
         self.browser.open(self.manage_container_path)
Index: /main/waeup.sirp/trunk/src/waeup/sirp/hostels/vocabularies.py
===================================================================
--- /main/waeup.sirp/trunk/src/waeup/sirp/hostels/vocabularies.py	(revision 7069)
+++ /main/waeup.sirp/trunk/src/waeup/sirp/hostels/vocabularies.py	(revision 7070)
@@ -19,10 +19,7 @@
         students = catalog.searchResults(current_session=(
             accommodation_session,accommodation_session))
-        try:
-            existing_students = [
-                context.__parent__[key].owner
-                for key in context.__parent__.keys()]
-        except AttributeError:
-            return {NOT_OCCUPIED:NOT_OCCUPIED}
+        existing_students = [
+            context.__parent__[key].owner
+            for key in context.__parent__.keys()]
         students = [student for student in students
                       if not student.student_id in existing_students]
