source: main/waeup.sirp/trunk/src/waeup/sirp/app.py @ 7094

Last change on this file since 7094 was 7063, checked in by uli, 13 years ago

Merge changes from branch ulif-extimgstore back into trunk.
Beside external image storage also waeupdocs should work again.

  • Property svn:eol-style set to native
File size: 2.7 KB
RevLine 
[3521]1import grok
[6362]2from zope.authentication.interfaces import IAuthentication
[6633]3from zope.component import getUtilitiesFor
[6137]4from zope.component.interfaces import ObjectEvent
[6362]5from zope.pluggableauth import PluggableAuthentication
[5054]6from waeup.sirp.authentication import setup_authentication
7from waeup.sirp.datacenter import DataCenter
[6633]8from waeup.sirp.students.container import StudentsContainer
[6952]9from waeup.sirp.hostels.container import HostelsContainer
[5016]10from waeup.sirp.interfaces import (
[6578]11    IUniversity, IWAeUPSIRPPluggable, IObjectUpgradeEvent, )
[4920]12from waeup.sirp.users import UserContainer
[6578]13from waeup.sirp.utils.logger import Logger
[6361]14from waeup.sirp.utils.helpers import attrs_to_fields
[6907]15from waeup.sirp.configuration import ConfigurationContainer
[4789]16
[6578]17class University(grok.Application, grok.Container, Logger):
[4789]18    """A university.
19    """
[4968]20    grok.implements(IUniversity)
[6129]21
[4789]22    # Setup authentication for this app. Note: this is only
23    # initialized, when a new instance of this app is created.
24    grok.local_utility(
25        PluggableAuthentication, provides = IAuthentication,
[5054]26        setup = setup_authentication,)
[5345]27
[6592]28    def __init__(self, *args, **kw):
29        super(University, self).__init__(*args, **kw)
[4789]30        self.setup()
[6592]31        return
[3521]32
[4789]33    def setup(self):
[5345]34        """Setup some hard-wired components.
35
36        Create local datacenter, containers for users, students and
37        the like.
38        """
[4789]39        self['users'] = UserContainer()
40        self['datacenter'] = DataCenter()
[6633]41        self['students'] = StudentsContainer()
[6907]42        self['configuration'] = ConfigurationContainer()
[6952]43        self['hostels'] = HostelsContainer()
[5016]44        self._createPlugins()
45
46    def _createPlugins(self):
47        """Create instances of all plugins defined somewhere.
48        """
[5071]49        for name, plugin in getUtilitiesFor(IWAeUPSIRPPluggable):
50            plugin.setup(self, name, self.logger)
51        return
[5421]52
53    def updatePlugins(self):
54        """Lookup all plugins and call their `update()` method.
55        """
[6138]56        name = getattr(self, '__name__', '<Unnamed>')
57        self.logger.info('Fire upgrade event for site %s' % name)
58        grok.notify(ObjectUpgradeEvent(self))
59        self.logger.info('Done.')
60        self.logger.info('Now upgrading any plugins.')
[5421]61        for name, plugin in getUtilitiesFor(IWAeUPSIRPPluggable):
62            plugin.update(self, name, self.logger)
[6138]63        self.logger.info('Plugin update finished.')
[5421]64        return
[6361]65attrs_to_fields(University)
[4884]66
[6137]67class ObjectUpgradeEvent(ObjectEvent):
68    """An event fired, when datacenter storage moves.
69    """
70    grok.implements(IObjectUpgradeEvent)
[6578]71
72@grok.subscribe(University, grok.IObjectAddedEvent)
[6839]73def handle_university_added(app, event):
[6578]74    app.logger.info('University `%s` added.' % getattr(app, '__name__', None))
75    return
Note: See TracBrowser for help on using the repository browser.