source: main/waeup.sirp/branches/ulif-extimgstore/src/waeup/sirp/app.py @ 7011

Last change on this file since 7011 was 7002, checked in by uli, 13 years ago

Throw in the complete mess of last 2 weeks. External file storage now works basically (tests pass), although there are lots of things still to remove, finetune, document, etc.

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