Index: WAeUP_SRP/trunk/skins/waeup_accommodation/book_reserved_bed.py
===================================================================
--- WAeUP_SRP/trunk/skins/waeup_accommodation/book_reserved_bed.py	(revision 1448)
+++ WAeUP_SRP/trunk/skins/waeup_accommodation/book_reserved_bed.py	(revision 1449)
@@ -15,5 +15,6 @@
 logger = logging.getLogger('Accommodation.BookReservedBed')
 
-change = REQUEST.has_key("reserve_and_change")
+#change = REQUEST.has_key("reserve_and_change")
+change = False
 release = REQUEST.has_key("release")
 reserve = REQUEST.has_key("reserve")
@@ -61,4 +62,7 @@
 res = acco_cat(bed = bid)
 psm = ''
+students = context.portal_url.getPortalObject().campus.students
+student_obj = getattr(students,sid)
+acco_id = "accommodation_%s" % context.getSessionId()
 while True:
     if not res:
@@ -81,4 +85,9 @@
             break
     if release:
+        if acco_id in student_obj.objectIds():
+            acco_doc = getattr(student_obj, acco_id).getContent()
+            if acco_doc.bed == bid:
+                psm = "Student %s has not reserved bed" % (sid, bid)
+                break
         if not already:
             psm = "Student %s already has no reserved beds" % (sid, already[0].bed)
@@ -104,7 +113,4 @@
         acco_cat.modifyRecord(bed=bed.bed,student='')
 
-students = context.portal_url.getPortalObject().campus.students
-student_obj = getattr(students,sid)
-acco_id = "accommodation_%s" % context.getSessionId()
 if reserve or change:
     acco_cat.modifyRecord(bed = bid, student = sid)
@@ -115,12 +121,10 @@
     psm = "Bed reserved for %s %s" % (sid,student.name)
 elif release:
-    acco_cat.modifyRecord(bed=bid,student='')
     if acco_id in student_obj.objectIds():
         acco_doc = getattr(student_obj, acco_id).getContent()
-        if acco_doc.bed == bid:
-            acco_doc.edit(mapping={'bed':bid + " (reservation cancelled by %s!)" % member})
+        if acco_doc.bed != bid:
+            acco_cat.modifyRecord(bed=bid,student='')
     logger.info('"%s","cancelled reservation %s by","%s"' % (member,bid,sid))
     psm = "%s removed from %s" % (student.name,bid)
-
 mode = 'view'
 return context.book_reserved_bed_form(rendered = "",
Index: WAeUP_SRP/trunk/skins/waeup_accommodation/book_reserved_bed_form.pt
===================================================================
--- WAeUP_SRP/trunk/skins/waeup_accommodation/book_reserved_bed_form.pt	(revision 1448)
+++ WAeUP_SRP/trunk/skins/waeup_accommodation/book_reserved_bed_form.pt	(revision 1449)
@@ -23,5 +23,5 @@
                  tal:attributes="value options/button"
                  tal:condition="not:creation" />
-          <input type="submit" tal:condition="python:mode !='view'"
+          <input type="submit" tal:condition="python:0 and mode !='view'"
                  class="standalone" 
                  name="reserve_and_change"
Index: WAeUP_SRP/trunk/skins/waeup_accommodation/change_bed.py
===================================================================
--- WAeUP_SRP/trunk/skins/waeup_accommodation/change_bed.py	(revision 1448)
+++ WAeUP_SRP/trunk/skins/waeup_accommodation/change_bed.py	(revision 1449)
@@ -57,5 +57,12 @@
         acco_doc.edit(mapping=d)
         return redirect("%s/%s/%s" % (students.absolute_url(),student,info['acco_id']))
+    student_obj = getattr(students,student_id)
+    acco_id = "accommodation_%s" % context.getSessionId()
+    if acco_id in student_obj.objectIds():
+        acco_doc = getattr(student_obj, acco_id).getContent()
+        if acco_doc.bed == bed:
+            acco_doc.edit(mapping={'bed':bed + " (cancelled by change bed %s!)" % member})
     logger.info('"%s", "new bed allocation failed","%s"' % (student_id,code))
+    logger.info('"%s","cancelled booking of %s"' % (member,bed,sid))
     redirect("%s/%s/%s" % (students.absolute_url(),student,info['acco_id']))
 
Index: WAeUP_SRP/trunk/skins/waeup_accommodation/release_bed.py
===================================================================
--- WAeUP_SRP/trunk/skins/waeup_accommodation/release_bed.py	(revision 1449)
+++ WAeUP_SRP/trunk/skins/waeup_accommodation/release_bed.py	(revision 1449)
@@ -0,0 +1,43 @@
+## Script (Python) "change_bed"
+##bind container=container
+##bind context=context
+##bind namespace=
+##bind script=script
+##bind subpath=traverse_subpath
+##parameters=
+##title=
+##
+# $Id$
+"""
+release an allocated bed
+"""
+import logging
+logger = logging.getLogger('Student.Accommodation.release_bed')
+
+request = context.REQUEST
+redirect = request.RESPONSE.redirect
+mtool = context.portal_membership
+wf = context.portal_workflow
+member = mtool.getAuthenticatedMember()
+member_id = str(member)
+path_info = request.get('PATH_INFO').split('/')
+
+if mtool.isAnonymousUser():
+    return None
+students = context.portal_url.getPortalObject().campus.students
+acco_cat = context.portal_accommodation
+#stud_cat = context.students_catalog
+student_id = context.getStudentId()
+
+if student_id is not None:
+    logger.info('"%s", "requests bed_release for", "%s"' % (member_id,student_id))
+    res = acco_cat(student=student_id)
+    if len(res) == 0:
+        logger.info('"%s", "no bed found"' % (student_id))
+        redirect("%s/%s" % (students.absolute_url(),student_id))
+    allocated_bed = res[0]
+    acco_cat.modifyRecord(bed=allocated_bed.bed,student='')
+    acco_doc = context.getContent()
+    acco_doc.edit(mapping={'bed':acco_doc.bed + " (cancelled by release bed %s!)" % member})
+    redirect("%s" % (context.absolute_url()))
+
