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

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

Add logger and add hostels container to site root.

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