source: main/waeup.kofa/trunk/src/waeup/kofa/mandates/container.py @ 10816

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

Let removeExpired return the number of deleted mandates.

  • Property svn:keywords set to Id
File size: 2.3 KB
RevLine 
[8846]1## $Id: container.py 8910 2012-07-04 07:52:21Z henrik $
2##
3## Copyright (C) 2012 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 mandate objects.
20"""
21import grok
22from datetime import datetime
23from grok import index
24from waeup.kofa.interfaces import IKofaPluggable
25from waeup.kofa.mandates.interfaces import IMandatesContainer, IMandate
26
27class MandatesContainer(grok.Container):
28    """This is a container for all kind of mandates.
29    """
30    grok.implements(IMandatesContainer)
31    grok.provides(IMandatesContainer)
32
33    def addMandate(self, mandate):
34        if not IMandate.providedBy(mandate):
35            raise TypeError(
36                'MandateContainers contain only IMandate instances')
37        self[mandate.mandate_id] = mandate
38        return
39
40    def removeExpired(self):
41        """Remove all expired mandates.
42        """
[8910]43        num_deleted = 0
[8846]44        for mandate in self.keys():
45            if self[mandate].expires < datetime.utcnow():
46                del self[mandate]
[8910]47                num_deleted += 1
48        return num_deleted
[8846]49
50class MandatesPlugin(grok.GlobalUtility):
51    """A plugin that creates container for mandates inside a university.
52    """
53    grok.implements(IKofaPluggable)
54    grok.name('mandates')
55
56    def setup(self, site, name, logger):
57        if 'mandates' in site.keys():
58            logger.warn('Could not create container for faculties in Kofa.')
59            return
60        site['mandates'] = MandatesContainer()
61        logger.info('Container for mandates created')
62        return
63
64    def update(self, site, name, logger):
65        if not 'mandates' in site.keys():
66            self.setup(site, name, logger)
Note: See TracBrowser for help on using the repository browser.