Ignore:
Timestamp:
12 Jun 2012, 07:36:23 (13 years ago)
Author:
Henrik Bettermann
Message:

Add expired property.

Location:
main/waeup.kofa/trunk/src/waeup/kofa/hostels
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/hostels/container.py

    r8685 r8686  
    2020"""
    2121import grok
     22import pytz
     23from datetime import datetime
    2224from waeup.kofa.hostels.interfaces import IHostelsContainer, IHostel
    2325from waeup.kofa.utils.logger import Logger
     
    6365        return self.logger_info(ob_class,target,comment)
    6466
     67    @property
     68    def expired(self):
     69        # Check if application has started ...
     70        if not self.startdate or (
     71            self.startdate > datetime.now(pytz.utc)):
     72            return True
     73        # ... or ended
     74        if not self.enddate or (
     75            self.enddate < datetime.now(pytz.utc)):
     76            return True
     77        return False
     78
    6579HostelsContainer = attrs_to_fields(HostelsContainer)
  • main/waeup.kofa/trunk/src/waeup/kofa/hostels/tests.py

    r8685 r8686  
    2222import tempfile
    2323import grok
     24import pytz
     25from datetime import datetime, timedelta
    2426from zope.event import notify
    25 
    2627from zope.interface.verify import verifyClass, verifyObject
    2728from zope.component.hooks import setSite, clearSite
     
    8687        self.assertRaises(
    8788            TypeError, hostel.addBed, department)
     89        # Application is expired if startdate or enddate are not set
     90        # or current datetime is outside application period.
     91        self.assertTrue(container.expired)
     92        delta = timedelta(days=10)
     93        container.startdate = datetime.now(pytz.utc) - delta
     94        self.assertTrue(container.expired)
     95        container.enddate = datetime.now(pytz.utc) + delta
     96        self.assertFalse(container.expired)
    8897
    8998class HostelsFullSetup(FunctionalTestCase):
Note: See TracChangeset for help on using the changeset viewer.