source: main/waeup.kofa/trunk/src/waeup/kofa/app.py @ 8855

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

Add mandates module.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.6 KB
RevLine 
[7193]1## $Id: app.py 8846 2012-06-29 08:19:47Z 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##
[3521]18import grok
[6362]19from zope.authentication.interfaces import IAuthentication
[6633]20from zope.component import getUtilitiesFor
[6137]21from zope.component.interfaces import ObjectEvent
[6362]22from zope.pluggableauth import PluggableAuthentication
[7811]23from waeup.kofa.authentication import setup_authentication
24from waeup.kofa.datacenter import DataCenter
25from waeup.kofa.students.container import StudentsContainer
26from waeup.kofa.hostels.container import HostelsContainer
[8846]27from waeup.kofa.mandates.container import MandatesContainer
[7811]28from waeup.kofa.interfaces import (
[7819]29    IUniversity, IKofaPluggable, IObjectUpgradeEvent, )
[7811]30from waeup.kofa.userscontainer import UsersContainer
31from waeup.kofa.utils.logger import Logger
32from waeup.kofa.utils.helpers import attrs_to_fields
33from waeup.kofa.configuration import ConfigurationContainer
[4789]34
[6578]35class University(grok.Application, grok.Container, Logger):
[4789]36    """A university.
37    """
[4968]38    grok.implements(IUniversity)
[6129]39
[4789]40    # Setup authentication for this app. Note: this is only
41    # initialized, when a new instance of this app is created.
42    grok.local_utility(
43        PluggableAuthentication, provides = IAuthentication,
[5054]44        setup = setup_authentication,)
[5345]45
[6592]46    def __init__(self, *args, **kw):
47        super(University, self).__init__(*args, **kw)
[4789]48        self.setup()
[6592]49        return
[3521]50
[4789]51    def setup(self):
[5345]52        """Setup some hard-wired components.
53
54        Create local datacenter, containers for users, students and
55        the like.
56        """
[7172]57        self['users'] = UsersContainer()
[4789]58        self['datacenter'] = DataCenter()
[6633]59        self['students'] = StudentsContainer()
[6907]60        self['configuration'] = ConfigurationContainer()
[6952]61        self['hostels'] = HostelsContainer()
[8846]62        self['mandates'] = MandatesContainer()
[5016]63        self._createPlugins()
64
65    def _createPlugins(self):
66        """Create instances of all plugins defined somewhere.
67        """
[7819]68        for name, plugin in getUtilitiesFor(IKofaPluggable):
[5071]69            plugin.setup(self, name, self.logger)
70        return
[5421]71
72    def updatePlugins(self):
73        """Lookup all plugins and call their `update()` method.
74        """
[6138]75        name = getattr(self, '__name__', '<Unnamed>')
76        self.logger.info('Fire upgrade event for site %s' % name)
77        grok.notify(ObjectUpgradeEvent(self))
78        self.logger.info('Done.')
79        self.logger.info('Now upgrading any plugins.')
[7819]80        for name, plugin in getUtilitiesFor(IKofaPluggable):
[5421]81            plugin.update(self, name, self.logger)
[6138]82        self.logger.info('Plugin update finished.')
[5421]83        return
[6361]84attrs_to_fields(University)
[4884]85
[6137]86class ObjectUpgradeEvent(ObjectEvent):
87    """An event fired, when datacenter storage moves.
88    """
89    grok.implements(IObjectUpgradeEvent)
[6578]90
91@grok.subscribe(University, grok.IObjectAddedEvent)
[6839]92def handle_university_added(app, event):
[6578]93    app.logger.info('University `%s` added.' % getattr(app, '__name__', None))
94    return
Note: See TracBrowser for help on using the repository browser.