Index: main/waeup.sirp/trunk/src/waeup/sirp/students/browser.py
===================================================================
--- main/waeup.sirp/trunk/src/waeup/sirp/students/browser.py	(revision 7062)
+++ main/waeup.sirp/trunk/src/waeup/sirp/students/browser.py	(revision 7068)
@@ -186,4 +186,6 @@
                 self.flash('Empty search string.')
             return
+        if self.searchtype == 'current_session':
+            self.searchterm = int(self.searchterm)
         self.hitlist = search(query=self.searchterm,
             searchtype=self.searchtype, view=self)
@@ -1178,10 +1180,6 @@
         deleted = []
         for id in child_id:
-            try:
-                del self.context[id]
-                deleted.append(id)
-            except:
-                self.flash('Could not delete %s: %s: %s' % (
-                        id, sys.exc_info()[0], sys.exc_info()[1]))
+            del self.context[id]
+            deleted.append(id)
         if len(deleted):
             self.flash('Successfully removed: %s' % ', '.join(deleted))
@@ -1295,6 +1293,6 @@
         coordinates = bed.getBedCoordinates()[1:]
         block, room_nr, bed_nr = coordinates
-        bedticket.bed_coordinates = '%s, Block %s, Room %s, Bed %s' % (
-            hall_title, block, room_nr, bed_nr)
+        bedticket.bed_coordinates = '%s, Block %s, Room %s, Bed %s (%s)' % (
+            hall_title, block, room_nr, bed_nr, bed.bed_type)
         key = str(acc_details['booking_session'])
         self.context[key] = bedticket
@@ -1381,45 +1379,55 @@
         student = self.context.getStudent()
         acc_details  = self.getAccommodationDetails(student)
+        if self.context.bed != None and \
+              'reserved' in self.context.bed.bed_type:
+            self.flash("Students in reserved beds can't be relocated.")
+            self.redirect(self.url(self.context))
+            return
         if acc_details['bt'] == self.context.bed_type and \
+                self.context.bed != None and \
                 self.context.bed.bed_type == self.context.bed_type:
-            self.flash("Bed category hasn't changed. Student can't be relocated.")
-            return
-        # Search a bed and exit if no bed is found
+            self.flash("Student can't be relocated.")
+            self.redirect(self.url(self.context))
+            return
+        # Search a bed
         cat = queryUtility(ICatalog, name='beds_catalog', default=None)
         entries = cat.searchResults(
-            bed_type=(acc_details['bt'],acc_details['bt']))
-        available_beds = [
-            entry for entry in entries if entry.owner == NOT_OCCUPIED]
-        if not available_beds:
-            self.flash('There is no free bed in your category %s.'
-                        % acc_details['bt'])
-            return
-        #entries = cat.searchResults(
-        #    owner=(student.student_id,student.student_id))
-        # Rlease old bed
-        try:
-            allocated_bed = self.context.bed
-            allocated_bed.owner = NOT_OCCUPIED
-            notify(grok.ObjectModifiedEvent(allocated_bed))
-        except AttributeError:
-            # Cannot happen but anyway...
-            pass
+            owner=(student.student_id,student.student_id))
+        if len(entries) and self.context.bed == None:
+            # If booking has been cancelled but other bed space has been
+            # manually allocated after cancellation use this bed
+            new_bed = [entry for entry in entries][0]
+        else:
+            # Search for other available beds
+            entries = cat.searchResults(
+                bed_type=(acc_details['bt'],acc_details['bt']))
+            available_beds = [
+                entry for entry in entries if entry.owner == NOT_OCCUPIED]
+            if available_beds:
+                new_bed = self.selectBed(available_beds)
+                new_bed.bookBed(student.student_id)
+            else:
+                self.flash('There is no free bed in your category %s.'
+                            % acc_details['bt'])
+                self.redirect(self.url(self.context))
+                return
+        # Rlease old bed if exists
+        if self.context.bed != None:
+            self.context.bed.owner = NOT_OCCUPIED
+            notify(grok.ObjectModifiedEvent(self.context.bed))
         # Alocate new bed
         self.context.bed_type = acc_details['bt']
-        bed = self.selectBed(available_beds)
-        bed.bookBed(student.student_id)
-        self.context.bed = bed
-        hall_title = bed.__parent__.hostel_name
-        coordinates = bed.getBedCoordinates()[1:]
+        self.context.bed = new_bed
+        hall_title = new_bed.__parent__.hostel_name
+        coordinates = new_bed.getBedCoordinates()[1:]
         block, room_nr, bed_nr = coordinates
-        self.context.bed_coordinates = '%s, Block %s, Room %s, Bed %s' % (
-            hall_title, block, room_nr, bed_nr)
-        self.flash('Student relocated and new bed booked: %s'
-            % self.context.bed_coordinates)
+        self.context.bed_coordinates = '%s, Block %s, Room %s, Bed %s (%s)' % (
+            hall_title, block, room_nr, bed_nr, new_bed.bed_type)
+        self.flash('Student relocated: %s' % self.context.bed_coordinates)
         self.redirect(self.url(self.context))
         return
 
     def render(self):
-        self.redirect(self.url(self.context, '@@index'))
+        #self.redirect(self.url(self.context, '@@index'))
         return
 
Index: main/waeup.sirp/trunk/src/waeup/sirp/students/browser_templates/containermanagepage.pt
===================================================================
--- main/waeup.sirp/trunk/src/waeup/sirp/students/browser_templates/containermanagepage.pt	(revision 7062)
+++ main/waeup.sirp/trunk/src/waeup/sirp/students/browser_templates/containermanagepage.pt	(revision 7068)
@@ -10,4 +10,5 @@
     <option value="student_id">with id</option>
     <option value="fullname">with name</option>
+    <option value="current_session">in session</option>
   </select>
 
Index: main/waeup.sirp/trunk/src/waeup/sirp/students/browser_templates/containerpage.pt
===================================================================
--- main/waeup.sirp/trunk/src/waeup/sirp/students/browser_templates/containerpage.pt	(revision 7062)
+++ main/waeup.sirp/trunk/src/waeup/sirp/students/browser_templates/containerpage.pt	(revision 7068)
@@ -12,4 +12,5 @@
     <option value="reg_number">with registration number</option>
     <option value="matric_number">with matriculation number</option>
+    <option value="current_session">in session</option>
   </select>
 
Index: main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_browser.py
===================================================================
--- main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_browser.py	(revision 7062)
+++ main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_browser.py	(revision 7068)
@@ -961,5 +961,5 @@
         self.browser.getLink("Relocate student").click()
         self.assertMatches(
-            "...Bed category hasn't changed...", self.browser.contents)
+            "...Student can't be relocated...", self.browser.contents)
         self.student.sex = u'f'
         self.browser.getLink("Relocate student").click()
@@ -977,15 +977,43 @@
         # Managers can relocate students if the bed's bed_type has changed
         bed1.bed_type = u'regular_female_fr'
-        bed2.bed_type = u'regular_male_reserved'
+        bed2.bed_type = u'regular_male_fr'
         notify(grok.ObjectModifiedEvent(bed1))
         notify(grok.ObjectModifiedEvent(bed2))
         self.browser.getLink("Relocate student").click()
         self.assertMatches(
-            "...Student relocated and new bed booked...", self.browser.contents)
+            "...Student relocated...", self.browser.contents)
         self.assertMatches(
             "... Hall 1, Block A, Room 101, Bed A...", self.browser.contents)
         self.assertMatches(bed1.owner, self.student_id)
         self.assertMatches(bed2.owner, NOT_OCCUPIED)
-        # Managers can delete bed tickets
+        # Managers can't relocate students if bed is reserved
+        self.student.sex = u'm'
+        bed1.bed_type = u'regular_female_reserved'
+        notify(grok.ObjectModifiedEvent(bed1))
+        self.browser.getLink("Relocate student").click()
+        self.assertMatches(
+            "...Students in reserved beds can't be relocated...",
+            self.browser.contents)
+        # Managers can relocate students if booking has been cancelled but
+        # other bed space has been manually allocated after cancellation
+        old_owner = bed1.releaseBed()
+        self.assertMatches(old_owner, self.student_id)
+        bed2.owner = self.student_id
+        self.browser.open(self.acco_student_path + '/2004')
+        self.assertMatches(
+            "...booking cancelled...", self.browser.contents)
+        self.browser.getLink("Relocate student").click()
+        # We didn't informed the catalog therefore the new owner is not found
+        self.assertMatches(
+            "...There is no free bed in your category regular_male_fr...",
+            self.browser.contents)
+        # Now we fire the event properly
+        notify(grok.ObjectModifiedEvent(bed2))
+        self.browser.getLink("Relocate student").click()
+        self.assertMatches(
+            "...Student relocated...", self.browser.contents)
+        self.assertMatches(
+            "... Hall 1, Block A, Room 101, Bed B...", self.browser.contents)
+          # Managers can delete bed tickets
         self.browser.open(self.acco_student_path)
         ctrl = self.browser.getControl(name='val_id')
