[5648] | 1 | ## |
---|
| 2 | ## root.py |
---|
| 3 | ## Login : <uli@pu.smp.net> |
---|
| 4 | ## Started on Thu Jan 20 04:17:59 2011 Uli Fouquet |
---|
| 5 | ## $Id$ |
---|
| 6 | ## |
---|
| 7 | ## Copyright (C) 2011 Uli Fouquet |
---|
| 8 | ## This program is free software; you can redistribute it and/or modify |
---|
| 9 | ## it under the terms of the GNU General Public License as published by |
---|
| 10 | ## the Free Software Foundation; either version 2 of the License, or |
---|
| 11 | ## (at your option) any later version. |
---|
| 12 | ## |
---|
| 13 | ## This program is distributed in the hope that it will be useful, |
---|
| 14 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | ## GNU General Public License for more details. |
---|
| 17 | ## |
---|
| 18 | ## You should have received a copy of the GNU General Public License |
---|
| 19 | ## along with this program; if not, write to the Free Software |
---|
| 20 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
| 21 | ## |
---|
| 22 | """ |
---|
| 23 | The root for applications. |
---|
| 24 | """ |
---|
| 25 | import grok |
---|
[5670] | 26 | from waeup.sirp.interfaces import IWAeUPSIRPPluggable |
---|
[5648] | 27 | from waeup.sirp.applications.interfaces import IApplicationsRoot |
---|
| 28 | |
---|
| 29 | class ApplicationsRoot(grok.Container): |
---|
| 30 | """The root of student applications-related components. |
---|
| 31 | """ |
---|
| 32 | grok.implements(IApplicationsRoot) |
---|
[5670] | 33 | |
---|
[5648] | 34 | def addApplicationContainer(self, container, name=None): |
---|
| 35 | """Add an application container. |
---|
| 36 | |
---|
| 37 | Adds an application container that implements `interface` |
---|
| 38 | under the name `name`. |
---|
| 39 | |
---|
[5670] | 40 | `container` |
---|
| 41 | the container instance to be added. Should |
---|
[5648] | 42 | implement :class:`IApplicationContainer`. |
---|
| 43 | |
---|
| 44 | `name` |
---|
| 45 | the name under which the container will be accessible. We |
---|
| 46 | usually use names like ``pume_2011`` to indicate, that the |
---|
| 47 | new container will contain student applications for a |
---|
| 48 | certain screening type (``pume``) and of the year 2011. |
---|
| 49 | |
---|
| 50 | """ |
---|
| 51 | self[name] = container |
---|
| 52 | return |
---|
[5670] | 53 | |
---|
| 54 | class ApplicationsPlugin(grok.GlobalUtility): |
---|
| 55 | """A WAeUPSIRPPlugin that creates an applications root in portal. |
---|
| 56 | |
---|
| 57 | This plugin should be called by a typical |
---|
| 58 | `waeup.sirp.app.Universtiy` instance on creation time. The |
---|
| 59 | :meth:`update` method normally can also be triggered manually over |
---|
| 60 | the main site configuration. |
---|
| 61 | |
---|
| 62 | Implements :class:`waeup.sirp.interfaces.IWAeUPSIRPPluggable` |
---|
| 63 | """ |
---|
| 64 | grok.name('applications') |
---|
| 65 | grok.implements(IWAeUPSIRPPluggable) |
---|
| 66 | log_prefix = 'ApplicationsPlugin' |
---|
| 67 | |
---|
| 68 | def setup(self, site, name, logger): |
---|
| 69 | """Create a new :class:`ApplicationsRoot` instance in `site`. |
---|
| 70 | """ |
---|
| 71 | site['applications'] = ApplicationsRoot() |
---|
| 72 | logger.info( |
---|
| 73 | '%s: Installed applications root.' % (self.log_prefix,) |
---|
| 74 | ) |
---|
| 75 | return |
---|
| 76 | |
---|
| 77 | def update(self, site, name, logger): |
---|
| 78 | """Update site wide ``applications`` root. |
---|
| 79 | |
---|
| 80 | If the site already contains a suitable ``applications`` root, |
---|
| 81 | leave it that way. If not create one and delete the old one if |
---|
| 82 | appropriate. |
---|
| 83 | """ |
---|
| 84 | app_folder = site.get('applications', None) |
---|
| 85 | site_name = getattr(site, '__name__', 'Unnamed Site?') |
---|
| 86 | if IApplicationsRoot.providedBy(app_folder): |
---|
| 87 | # Applications up to date. Return. |
---|
| 88 | logger.info( |
---|
| 89 | '%s: Updating site at %s: Nothing to do.' % ( |
---|
| 90 | self.log_prefix, site_name,) |
---|
| 91 | ) |
---|
| 92 | return |
---|
| 93 | elif app_folder is not None: |
---|
| 94 | # Applications need update. Remove old instance. |
---|
| 95 | logger.warn( |
---|
| 96 | '%s: Outdated applications folder detected at site %s.' |
---|
| 97 | 'Removing it.' % (self.log_prefix, site_name) |
---|
| 98 | ) |
---|
| 99 | del site['applications'] |
---|
| 100 | # Add new applications. |
---|
| 101 | logger.info( |
---|
| 102 | '%s: Updating site at %s. Installing ' |
---|
| 103 | 'applications.' % (self.log_prefix, site_name,) |
---|
| 104 | ) |
---|
| 105 | self.setup(site, name, logger) |
---|
| 106 | return |
---|