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

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

Remove old student package and replace by new students package which even contains the first browser UIs (fully tested)

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