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

Last change on this file since 9426 was 9217, checked in by uli, 12 years ago

Merge changes from uli-async-update back into trunk.

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