[7193] | 1 | ## $Id: app.py 14638 2017-03-21 10:13:41Z henrik $ |
---|
| 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 | ## |
---|
[3521] | 18 | import grok |
---|
[6362] | 19 | from zope.authentication.interfaces import IAuthentication |
---|
[9217] | 20 | from zope.component import getUtility, getUtilitiesFor |
---|
[6137] | 21 | from zope.component.interfaces import ObjectEvent |
---|
[6362] | 22 | from zope.pluggableauth import PluggableAuthentication |
---|
[7811] | 23 | from waeup.kofa.authentication import setup_authentication |
---|
| 24 | from waeup.kofa.datacenter import DataCenter |
---|
[8846] | 25 | from waeup.kofa.mandates.container import MandatesContainer |
---|
[7811] | 26 | from waeup.kofa.interfaces import ( |
---|
[9217] | 27 | IUniversity, IKofaPluggable, IObjectUpgradeEvent, IJobManager, |
---|
| 28 | VIRT_JOBS_CONTAINER_NAME) |
---|
[7811] | 29 | from waeup.kofa.userscontainer import UsersContainer |
---|
| 30 | from waeup.kofa.utils.logger import Logger |
---|
| 31 | from waeup.kofa.utils.helpers import attrs_to_fields |
---|
| 32 | from waeup.kofa.configuration import ConfigurationContainer |
---|
[4789] | 33 | |
---|
[12476] | 34 | |
---|
[6578] | 35 | class University(grok.Application, grok.Container, Logger): |
---|
[4789] | 36 | """A university. |
---|
| 37 | """ |
---|
[4968] | 38 | grok.implements(IUniversity) |
---|
[6129] | 39 | |
---|
[4789] | 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( |
---|
[12476] | 43 | PluggableAuthentication, provides=IAuthentication, |
---|
| 44 | setup=setup_authentication,) |
---|
[5345] | 45 | |
---|
[6592] | 46 | def __init__(self, *args, **kw): |
---|
| 47 | super(University, self).__init__(*args, **kw) |
---|
[4789] | 48 | self.setup() |
---|
[6592] | 49 | return |
---|
[3521] | 50 | |
---|
[4789] | 51 | def setup(self): |
---|
[5345] | 52 | """Setup some hard-wired components. |
---|
| 53 | |
---|
| 54 | Create local datacenter, containers for users, students and |
---|
| 55 | the like. |
---|
| 56 | """ |
---|
[9217] | 57 | from waeup.kofa.students.container import StudentsContainer |
---|
| 58 | from waeup.kofa.hostels.container import HostelsContainer |
---|
| 59 | |
---|
[7172] | 60 | self['users'] = UsersContainer() |
---|
[4789] | 61 | self['datacenter'] = DataCenter() |
---|
[6633] | 62 | self['students'] = StudentsContainer() |
---|
[6907] | 63 | self['configuration'] = ConfigurationContainer() |
---|
[6952] | 64 | self['hostels'] = HostelsContainer() |
---|
[8846] | 65 | self['mandates'] = MandatesContainer() |
---|
[5016] | 66 | self._createPlugins() |
---|
| 67 | |
---|
| 68 | def _createPlugins(self): |
---|
| 69 | """Create instances of all plugins defined somewhere. |
---|
| 70 | """ |
---|
[7819] | 71 | for name, plugin in getUtilitiesFor(IKofaPluggable): |
---|
[5071] | 72 | plugin.setup(self, name, self.logger) |
---|
| 73 | return |
---|
[5421] | 74 | |
---|
[9217] | 75 | def traverse(self, name): |
---|
| 76 | if name == VIRT_JOBS_CONTAINER_NAME: |
---|
| 77 | return getUtility(IJobManager) |
---|
| 78 | return None |
---|
| 79 | |
---|
[5421] | 80 | def updatePlugins(self): |
---|
[14511] | 81 | """Lookup plugins and call their `update()` method to |
---|
| 82 | upgrade Kofa's database since software version 1.4 (2016-01-14). |
---|
[5421] | 83 | """ |
---|
[14511] | 84 | getUtility(IKofaPluggable, name='faculties').update( |
---|
| 85 | self, 'faculties', self.logger) |
---|
| 86 | getUtility(IKofaPluggable, name='departments').update( |
---|
| 87 | self, 'departments', self.logger) |
---|
[13617] | 88 | getUtility(IKofaPluggable, name='certificates').update( |
---|
| 89 | self, 'certificates', self.logger) |
---|
[14638] | 90 | getUtility(IKofaPluggable, name='certcourses').update( |
---|
| 91 | self, 'certcourses', self.logger) |
---|
[5421] | 92 | return |
---|
[6361] | 93 | attrs_to_fields(University) |
---|
[4884] | 94 | |
---|
[12476] | 95 | |
---|
[6137] | 96 | class ObjectUpgradeEvent(ObjectEvent): |
---|
| 97 | """An event fired, when datacenter storage moves. |
---|
| 98 | """ |
---|
| 99 | grok.implements(IObjectUpgradeEvent) |
---|
[6578] | 100 | |
---|
[12476] | 101 | |
---|
[6578] | 102 | @grok.subscribe(University, grok.IObjectAddedEvent) |
---|
[6839] | 103 | def handle_university_added(app, event): |
---|
[11477] | 104 | """If a university is added, a message is logged. |
---|
| 105 | """ |
---|
[6578] | 106 | app.logger.info('University `%s` added.' % getattr(app, '__name__', None)) |
---|
| 107 | return |
---|