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

Last change on this file since 7002 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
Line 
1import grok
2from hurry.file.interfaces import IFileRetrieval
3from zope.authentication.interfaces import IAuthentication
4from zope.component import getUtilitiesFor
5from zope.component.interfaces import ObjectEvent
6from zope.pluggableauth import PluggableAuthentication
7from waeup.sirp.authentication import setup_authentication
8from waeup.sirp.datacenter import DataCenter
9from waeup.sirp.students.container import StudentsContainer
10from waeup.sirp.hostels.container import HostelsContainer
11from waeup.sirp.imagestorage import (
12    ImageStorageFileRetrieval, ImageStorage, ExtFileStore,)
13from waeup.sirp.interfaces import (
14    IUniversity, IWAeUPSIRPPluggable, IObjectUpgradeEvent, )
15from waeup.sirp.users import UserContainer
16from waeup.sirp.utils.logger import Logger
17from waeup.sirp.utils.helpers import attrs_to_fields
18from waeup.sirp.configuration import ConfigurationContainer
19
20class University(grok.Application, grok.Container, Logger):
21    """A university.
22    """
23    grok.implements(IUniversity)
24
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,
29        setup = setup_authentication,)
30
31    #grok.local_utility(
32    #    ImageStorageFileRetrieval, provides = IFileRetrieval)
33
34    #grok.local_utility(
35    #    ExtFileStore, provides = IFileRetrieval)
36    def __init__(self, *args, **kw):
37        super(University, self).__init__(*args, **kw)
38        self.setup()
39        return
40
41    def setup(self):
42        """Setup some hard-wired components.
43
44        Create local datacenter, containers for users, students and
45        the like.
46        """
47        self['users'] = UserContainer()
48        self['datacenter'] = DataCenter()
49        self['images'] = ImageStorage()
50        self['students'] = StudentsContainer()
51        self['configuration'] = ConfigurationContainer()
52        self['hostels'] = HostelsContainer()
53        self._createPlugins()
54
55    def _createPlugins(self):
56        """Create instances of all plugins defined somewhere.
57        """
58        for name, plugin in getUtilitiesFor(IWAeUPSIRPPluggable):
59            plugin.setup(self, name, self.logger)
60        return
61
62    def updatePlugins(self):
63        """Lookup all plugins and call their `update()` method.
64        """
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.')
70        for name, plugin in getUtilitiesFor(IWAeUPSIRPPluggable):
71            plugin.update(self, name, self.logger)
72        self.logger.info('Plugin update finished.')
73        return
74attrs_to_fields(University)
75
76class ObjectUpgradeEvent(ObjectEvent):
77    """An event fired, when datacenter storage moves.
78    """
79    grok.implements(IObjectUpgradeEvent)
80
81@grok.subscribe(University, grok.IObjectAddedEvent)
82def handle_university_added(app, event):
83    app.logger.info('University `%s` added.' % getattr(app, '__name__', None))
84    return
Note: See TracBrowser for help on using the repository browser.