Ignore:
Timestamp:
12 Jun 2012, 09:58:03 (13 years ago)
Author:
Henrik Bettermann
Message:

Check if booking perios is expired before allocating a bed.

To do: The update method of BedTicketAddPage? is too long and code has to be split and moved to data models.

Location:
main/waeup.kofa/trunk/src/waeup/kofa/students
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/students/browser.py

    r8685 r8688  
    6262from waeup.kofa.browser.resources import toggleall
    6363from waeup.kofa.hostels.hostel import NOT_OCCUPIED
    64 from waeup.kofa.utils.helpers import get_current_principal
     64from waeup.kofa.utils.helpers import get_current_principal, to_timezone
    6565
    6666def write_log_message(view, message):
     
    12301230        students_utils = getUtility(IStudentsUtils)
    12311231        acc_details  = students_utils.getAccommodationDetails(student)
     1232        if acc_details.get('expired', False):
     1233            startdate = acc_details.get('startdate')
     1234            enddate = acc_details.get('enddate')
     1235            if startdate and enddate:
     1236                tz = getUtility(IKofaUtils).tzinfo
     1237                startdate = to_timezone(
     1238                    startdate, tz).strftime("%d/%m/%Y %H:%M:%S")
     1239                enddate = to_timezone(
     1240                    enddate, tz).strftime("%d/%m/%Y %H:%M:%S")
     1241                self.flash(_("Outside booking period: ${a} - ${b}",
     1242                    mapping = {'a': startdate, 'b': enddate}))
     1243            else:
     1244                self.flash(_("Outside booking period."))
     1245            self.redirect(self.url(self.context))
     1246            return
    12321247        if not acc_details:
    12331248            self.flash(_("Your data are incomplete."))
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py

    r8685 r8688  
    2121import shutil
    2222import tempfile
     23import pytz
     24from datetime import datetime, timedelta
    2325from StringIO import StringIO
    24 from datetime import datetime
    2526import os
    2627import grok
     
    171172            self.course, level=100)
    172173
    173         # Configure university
     174        # Configure university and hostels
    174175        self.app['hostels'].accommodation_states = ['admitted']
    175176        self.app['hostels'].accommodation_session = 2004
     177        delta = timedelta(days=10)
     178        self.app['hostels'].startdate = datetime.now(pytz.utc) - delta
     179        self.app['hostels'].enddate = datetime.now(pytz.utc) + delta
    176180        self.app['configuration'].carry_over = True
    177181        configuration = createObject('waeup.SessionConfiguration')
     
    17491753        sfeseries, sfenumber = parts
    17501754
    1751         # Students can use HOS code and book a bed space with it
     1755        # Students can use HOS code and book a bed space with it ...
    17521756        self.browser.open(self.acco_path)
     1757        # ... but not if booking period has expired ...
     1758        self.app['hostels'].enddate = datetime.now(pytz.utc)
     1759        self.browser.getLink("Book accommodation").click()
     1760        self.assertMatches('...Outside booking period: ...',
     1761                           self.browser.contents)
     1762        self.app['hostels'].enddate = datetime.now(pytz.utc) + timedelta(days=10)
     1763        # ... or student is not the an allowed state ...
    17531764        self.browser.getLink("Book accommodation").click()
    17541765        self.assertMatches('...You are in the wrong...',
     
    17581769        self.assertMatches('...Activation Code:...',
    17591770                           self.browser.contents)
     1771        # Student can't used faked ACs ...
    17601772        self.browser.getControl(name="ac_series").value = u'nonsense'
    17611773        self.browser.getControl(name="ac_number").value = sfenumber
     
    17631775        self.assertMatches('...Activation code is invalid...',
    17641776                           self.browser.contents)
     1777        # ... or ACs owned by somebody else.
    17651778        ac.owner = u'Anybody'
    17661779        self.browser.getControl(name="ac_series").value = sfeseries
  • main/waeup.kofa/trunk/src/waeup/kofa/students/utils.py

    r8685 r8688  
    323323        d['booking_session'] = hostels.accommodation_session
    324324        d['allowed_states'] = hostels.accommodation_states
     325        d['startdate'] = hostels.startdate
     326        d['enddate'] = hostels.enddate
     327        d['expired'] = hostels.expired
    325328        # Determine bed type
    326329        studycourse = student['studycourse']
Note: See TracChangeset for help on using the changeset viewer.