source: main/waeup.kofa/branches/uli-rm-bootstrap/src/waeup/kofa/app.py @ 17958

Last change on this file since 17958 was 14671, checked in by uli, 8 years ago

Activate new plugin. Untested.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.9 KB
Line 
1## $Id: app.py 14671 2017-04-06 14:07:54Z uli $
2##
3## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann
4## This program is free software; you can redistribute it and/or modify
5## it under the terms of the GNU General Public License as published by
6## the Free Software Foundation; either version 2 of the License, or
7## (at your option) any later version.
8##
9## This program is distributed in the hope that it will be useful,
10## but WITHOUT ANY WARRANTY; without even the implied warranty of
11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12## GNU General Public License for more details.
13##
14## You should have received a copy of the GNU General Public License
15## along with this program; if not, write to the Free Software
16## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17##
18import grok
19from zope.authentication.interfaces import IAuthentication
20from zope.component import getUtility, getUtilitiesFor
21from zope.component.interfaces import ObjectEvent
22from zope.pluggableauth import PluggableAuthentication
23from waeup.kofa.authentication import setup_authentication
24from waeup.kofa.datacenter import DataCenter
25from waeup.kofa.mandates.container import MandatesContainer
26from waeup.kofa.interfaces import (
27    IUniversity, IKofaPluggable, IObjectUpgradeEvent, IJobManager,
28    VIRT_JOBS_CONTAINER_NAME)
29from waeup.kofa.userscontainer import UsersContainer
30from waeup.kofa.utils.logger import Logger
31from waeup.kofa.utils.helpers import attrs_to_fields
32from waeup.kofa.configuration import ConfigurationContainer
33
34
35class University(grok.Application, grok.Container, Logger):
36    """A university.
37    """
38    grok.implements(IUniversity)
39
40    # Setup authentication for this app. Note: this is only
41    # initialized, when a new instance of this app is created.
42    grok.local_utility(
43        PluggableAuthentication, provides=IAuthentication,
44        setup=setup_authentication,)
45
46    def __init__(self, *args, **kw):
47        super(University, self).__init__(*args, **kw)
48        self.setup()
49        return
50
51    def setup(self):
52        """Setup some hard-wired components.
53
54        Create local datacenter, containers for users, students and
55        the like.
56        """
57        from waeup.kofa.students.container import StudentsContainer
58        from waeup.kofa.hostels.container import HostelsContainer
59
60        self['users'] = UsersContainer()
61        self['datacenter'] = DataCenter()
62        self['students'] = StudentsContainer()
63        self['configuration'] = ConfigurationContainer()
64        self['hostels'] = HostelsContainer()
65        self['mandates'] = MandatesContainer()
66        self._createPlugins()
67
68    def _createPlugins(self):
69        """Create instances of all plugins defined somewhere.
70        """
71        for name, plugin in getUtilitiesFor(IKofaPluggable):
72            plugin.setup(self, name, self.logger)
73        return
74
75    def traverse(self, name):
76        if name == VIRT_JOBS_CONTAINER_NAME:
77            return getUtility(IJobManager)
78        return None
79
80    def updatePlugins(self):
81        """Lookup an arbitrarily selected set of plugins and call their
82        `update()` method to upgrade Kofa's database since software version 1.4
83        (2016-01-14).
84
85        XXX: This method does not run all plugins registered.
86
87        XXX: Tests for this method were disabled.
88        """
89        for name in ['faculties', 'departments', 'certificates', 'certcourses',
90                     'site-pluggable-auth']:
91            getUtility(IKofaPluggable, name=name).update(
92                self, name, self.logger)
93        return
94attrs_to_fields(University)
95
96
97class ObjectUpgradeEvent(ObjectEvent):
98    """An event fired, when datacenter storage moves.
99    """
100    grok.implements(IObjectUpgradeEvent)
101
102
103@grok.subscribe(University, grok.IObjectAddedEvent)
104def handle_university_added(app, event):
105    """If a university is added, a message is logged.
106    """
107    app.logger.info('University `%s` added.' % getattr(app, '__name__', None))
108    return
Note: See TracBrowser for help on using the repository browser.