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

Last change on this file since 6932 was 6907, checked in by Henrik Bettermann, 13 years ago

Implement a configuration container. Transfer attributes from University class to ConfigurationContainer? class.

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