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

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