Index: /main/waeup.kofa/trunk/src/waeup/kofa/students/browser.py
===================================================================
--- /main/waeup.kofa/trunk/src/waeup/kofa/students/browser.py	(revision 8687)
+++ /main/waeup.kofa/trunk/src/waeup/kofa/students/browser.py	(revision 8688)
@@ -62,5 +62,5 @@
 from waeup.kofa.browser.resources import toggleall
 from waeup.kofa.hostels.hostel import NOT_OCCUPIED
-from waeup.kofa.utils.helpers import get_current_principal
+from waeup.kofa.utils.helpers import get_current_principal, to_timezone
 
 def write_log_message(view, message):
@@ -1230,4 +1230,19 @@
         students_utils = getUtility(IStudentsUtils)
         acc_details  = students_utils.getAccommodationDetails(student)
+        if acc_details.get('expired', False):
+            startdate = acc_details.get('startdate')
+            enddate = acc_details.get('enddate')
+            if startdate and enddate:
+                tz = getUtility(IKofaUtils).tzinfo
+                startdate = to_timezone(
+                    startdate, tz).strftime("%d/%m/%Y %H:%M:%S")
+                enddate = to_timezone(
+                    enddate, tz).strftime("%d/%m/%Y %H:%M:%S")
+                self.flash(_("Outside booking period: ${a} - ${b}",
+                    mapping = {'a': startdate, 'b': enddate}))
+            else:
+                self.flash(_("Outside booking period."))
+            self.redirect(self.url(self.context))
+            return
         if not acc_details:
             self.flash(_("Your data are incomplete."))
Index: /main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py
===================================================================
--- /main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py	(revision 8687)
+++ /main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py	(revision 8688)
@@ -21,6 +21,7 @@
 import shutil
 import tempfile
+import pytz
+from datetime import datetime, timedelta
 from StringIO import StringIO
-from datetime import datetime
 import os
 import grok
@@ -171,7 +172,10 @@
             self.course, level=100)
 
-        # Configure university
+        # Configure university and hostels
         self.app['hostels'].accommodation_states = ['admitted']
         self.app['hostels'].accommodation_session = 2004
+        delta = timedelta(days=10)
+        self.app['hostels'].startdate = datetime.now(pytz.utc) - delta
+        self.app['hostels'].enddate = datetime.now(pytz.utc) + delta
         self.app['configuration'].carry_over = True
         configuration = createObject('waeup.SessionConfiguration')
@@ -1749,6 +1753,13 @@
         sfeseries, sfenumber = parts
 
-        # Students can use HOS code and book a bed space with it
+        # Students can use HOS code and book a bed space with it ...
         self.browser.open(self.acco_path)
+        # ... but not if booking period has expired ...
+        self.app['hostels'].enddate = datetime.now(pytz.utc)
+        self.browser.getLink("Book accommodation").click()
+        self.assertMatches('...Outside booking period: ...',
+                           self.browser.contents)
+        self.app['hostels'].enddate = datetime.now(pytz.utc) + timedelta(days=10)
+        # ... or student is not the an allowed state ...
         self.browser.getLink("Book accommodation").click()
         self.assertMatches('...You are in the wrong...',
@@ -1758,4 +1769,5 @@
         self.assertMatches('...Activation Code:...',
                            self.browser.contents)
+        # Student can't used faked ACs ...
         self.browser.getControl(name="ac_series").value = u'nonsense'
         self.browser.getControl(name="ac_number").value = sfenumber
@@ -1763,4 +1775,5 @@
         self.assertMatches('...Activation code is invalid...',
                            self.browser.contents)
+        # ... or ACs owned by somebody else.
         ac.owner = u'Anybody'
         self.browser.getControl(name="ac_series").value = sfeseries
Index: /main/waeup.kofa/trunk/src/waeup/kofa/students/utils.py
===================================================================
--- /main/waeup.kofa/trunk/src/waeup/kofa/students/utils.py	(revision 8687)
+++ /main/waeup.kofa/trunk/src/waeup/kofa/students/utils.py	(revision 8688)
@@ -323,4 +323,7 @@
         d['booking_session'] = hostels.accommodation_session
         d['allowed_states'] = hostels.accommodation_states
+        d['startdate'] = hostels.startdate
+        d['enddate'] = hostels.enddate
+        d['expired'] = hostels.expired
         # Determine bed type
         studycourse = student['studycourse']
