source: main/waeup.kofa/branches/uli-zc-async/src/waeup/kofa/hostels/container.py @ 10371

Last change on this file since 10371 was 9211, checked in by uli, 12 years ago

Rollback r9209. Looks like multiple merges from trunk confuse svn when merging back into trunk.

  • Property svn:keywords set to Id
File size: 2.5 KB
Line 
1## $Id: container.py 9211 2012-09-21 08:19:35Z uli $
2##
3## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann
4## This program is free software; you can redistribute it and/or modify
5## it under the terms of the GNU General Public License as published by
6## the Free Software Foundation; either version 2 of the License, or
7## (at your option) any later version.
8##
9## This program is distributed in the hope that it will be useful,
10## but WITHOUT ANY WARRANTY; without even the implied warranty of
11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12## GNU General Public License for more details.
13##
14## You should have received a copy of the GNU General Public License
15## along with this program; if not, write to the Free Software
16## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17##
18"""
19Containers which contain hostels.
20"""
21import grok
22import pytz
23from datetime import datetime
24from waeup.kofa.hostels.interfaces import IHostelsContainer, IHostel
25from waeup.kofa.utils.logger import Logger
26from waeup.kofa.utils.helpers import attrs_to_fields
27
28class HostelsContainer(grok.Container, Logger):
29    """This is a container for all kind of hostels.
30    """
31    grok.implements(IHostelsContainer)
32    grok.provides(IHostelsContainer)
33
34    def __init__(self):
35        super(HostelsContainer, self).__init__()
36        return
37
38    def archive(self, id=None):
39        raise NotImplementedError()
40
41    def clear(self, id=None, archive=True):
42        raise NotImplementedError()
43
44    def addHostel(self, hostel):
45        """Add a hostel.
46        """
47        if not IHostel.providedBy(hostel):
48            raise TypeError(
49                'HostelsContainers contain only IHostel instances')
50        self[hostel.hostel_id] = hostel
51        return
52
53    logger_name = 'waeup.kofa.${sitename}.hostels'
54    logger_filename = 'hostels.log'
55
56    def logger_info(self, ob_class, target, comment=None):
57        """Get the logger's info method.
58        """
59        self.logger.info('%s - %s - %s' % (
60                ob_class, target, comment))
61        return
62
63    def loggerInfo(self, ob_class, comment=None):
64        target = self.__name__
65        return self.logger_info(ob_class,target,comment)
66
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
79HostelsContainer = attrs_to_fields(HostelsContainer)
Note: See TracBrowser for help on using the repository browser.