source: main/waeup.kofa/branches/0.2/src/waeup/kofa/hostels/container.py @ 15284

Last change on this file since 15284 was 9197, checked in by Henrik Bettermann, 12 years ago

Add view and content component methods to clear hostels.

  • Property svn:keywords set to Id
File size: 2.7 KB
Line 
1## $Id: container.py 9197 2012-09-18 16:24:21Z henrik $
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    def clearAllHostels(self):
54        """Clear all hostels.
55        """
56        for hostel in self.values():
57            hostel.clearHostel()
58        return
59
60    logger_name = 'waeup.kofa.${sitename}.hostels'
61    logger_filename = 'hostels.log'
62
63    def logger_info(self, ob_class, target, comment=None):
64        """Get the logger's info method.
65        """
66        self.logger.info('%s - %s - %s' % (
67                ob_class, target, comment))
68        return
69
70    def loggerInfo(self, ob_class, comment=None):
71        target = self.__name__
72        return self.logger_info(ob_class,target,comment)
73
74    @property
75    def expired(self):
76        # Check if application has started ...
77        if not self.startdate or (
78            self.startdate > datetime.now(pytz.utc)):
79            return True
80        # ... or ended
81        if not self.enddate or (
82            self.enddate < datetime.now(pytz.utc)):
83            return True
84        return False
85
86HostelsContainer = attrs_to_fields(HostelsContainer)
Note: See TracBrowser for help on using the repository browser.