source: main/waeup.kofa/trunk/src/waeup/kofa/hostels/container.py @ 13228

Last change on this file since 13228 was 13166, checked in by Henrik Bettermann, 9 years ago

Adjust logging methods in the various section.

  • Property svn:keywords set to Id
File size: 2.4 KB
RevLine 
[7195]1## $Id: container.py 13166 2015-07-13 08:20:23Z henrik $
2##
[6951]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
[8686]22import pytz
23from datetime import datetime
[7811]24from waeup.kofa.hostels.interfaces import IHostelsContainer, IHostel
25from waeup.kofa.utils.logger import Logger
[8685]26from waeup.kofa.utils.helpers import attrs_to_fields
[6951]27
[6952]28class HostelsContainer(grok.Container, Logger):
[6951]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
[6952]38    def addHostel(self, hostel):
39        """Add a hostel.
40        """
41        if not IHostel.providedBy(hostel):
42            raise TypeError(
43                'HostelsContainers contain only IHostel instances')
44        self[hostel.hostel_id] = hostel
45        return
46
[9197]47    def clearAllHostels(self):
48        """Clear all hostels.
49        """
50        for hostel in self.values():
51            hostel.clearHostel()
52        return
53
[8686]54    @property
55    def expired(self):
56        # Check if application has started ...
57        if not self.startdate or (
58            self.startdate > datetime.now(pytz.utc)):
59            return True
60        # ... or ended
61        if not self.enddate or (
62            self.enddate < datetime.now(pytz.utc)):
63            return True
64        return False
65
[13166]66    logger_name = 'waeup.kofa.${sitename}.hostels'
67    logger_filename = 'hostels.log'
68
69    def writeLogMessage(self, view, message):
70        ob_class = view.__implemented__.__name__.replace('waeup.kofa.','')
71        self.logger.info(
72            '%s - %s - %s' % (ob_class, self.__name__, message))
73        return
74
[8685]75HostelsContainer = attrs_to_fields(HostelsContainer)
Note: See TracBrowser for help on using the repository browser.