source: main/waeup.kofa/branches/uli-zc-async/src/waeup/kofa/app.py @ 10687

Last change on this file since 10687 was 9211, checked in by uli, 12 years ago

Rollback r9209. Looks like multiple merges from trunk confuse svn when merging back into trunk.

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