[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 | """ |
---|
[5676] | 23 | The root for applicants. |
---|
[5648] | 24 | """ |
---|
| 25 | import grok |
---|
[5670] | 26 | from waeup.sirp.interfaces import IWAeUPSIRPPluggable |
---|
[5676] | 27 | from waeup.sirp.applicants.interfaces import IApplicantsRoot |
---|
[5648] | 28 | |
---|
[5676] | 29 | class ApplicantsRoot(grok.Container): |
---|
| 30 | """The root of applicants-related components. It contains primarily |
---|
| 31 | containers for applicants. |
---|
[5648] | 32 | """ |
---|
[5676] | 33 | grok.implements(IApplicantsRoot) |
---|
[5670] | 34 | |
---|
[5676] | 35 | def addApplicantsContainer(self, container, name=None): |
---|
| 36 | """Add an applicants container. |
---|
[5648] | 37 | |
---|
[5676] | 38 | Adds an applicants container that implements `interface` |
---|
[5648] | 39 | under the name `name`. |
---|
| 40 | |
---|
[5670] | 41 | `container` |
---|
| 42 | the container instance to be added. Should |
---|
[5676] | 43 | implement :class:`IApplicantsContainer`. |
---|
[5648] | 44 | |
---|
| 45 | `name` |
---|
| 46 | the name under which the container will be accessible. We |
---|
| 47 | usually use names like ``pume_2011`` to indicate, that the |
---|
[5676] | 48 | new container will contain student applicants for a |
---|
[5648] | 49 | certain screening type (``pume``) and of the year 2011. |
---|
| 50 | |
---|
| 51 | """ |
---|
| 52 | self[name] = container |
---|
| 53 | return |
---|
[5670] | 54 | |
---|
[5676] | 55 | class ApplicantsPlugin(grok.GlobalUtility): |
---|
| 56 | """A WAeUPSIRPPlugin that creates an applicants root in portal. |
---|
[5670] | 57 | |
---|
| 58 | This plugin should be called by a typical |
---|
| 59 | `waeup.sirp.app.Universtiy` instance on creation time. The |
---|
| 60 | :meth:`update` method normally can also be triggered manually over |
---|
| 61 | the main site configuration. |
---|
| 62 | |
---|
| 63 | Implements :class:`waeup.sirp.interfaces.IWAeUPSIRPPluggable` |
---|
| 64 | """ |
---|
[5676] | 65 | grok.name('applicants') |
---|
[5670] | 66 | grok.implements(IWAeUPSIRPPluggable) |
---|
[5676] | 67 | log_prefix = 'ApplicantsPlugin' |
---|
[5670] | 68 | |
---|
| 69 | def setup(self, site, name, logger): |
---|
[5676] | 70 | """Create a new :class:`ApplicantsRoot` instance in `site`. |
---|
[5670] | 71 | """ |
---|
[5676] | 72 | site['applicants'] = ApplicantsRoot() |
---|
[5670] | 73 | logger.info( |
---|
[5676] | 74 | '%s: Installed applicants root.' % (self.log_prefix,) |
---|
[5670] | 75 | ) |
---|
| 76 | return |
---|
| 77 | |
---|
| 78 | def update(self, site, name, logger): |
---|
[5676] | 79 | """Update site wide ``applicants`` root. |
---|
[5670] | 80 | |
---|
[5676] | 81 | If the site already contains a suitable ``applicants`` root, |
---|
[5670] | 82 | leave it that way. If not create one and delete the old one if |
---|
| 83 | appropriate. |
---|
| 84 | """ |
---|
[5676] | 85 | app_folder = site.get('applicants', None) |
---|
[5684] | 86 | site_name = getattr(site, '__name__', '<Unnamed Site>') |
---|
[5676] | 87 | if IApplicantsRoot.providedBy(app_folder): |
---|
| 88 | # Applicants up to date. Return. |
---|
[5670] | 89 | logger.info( |
---|
| 90 | '%s: Updating site at %s: Nothing to do.' % ( |
---|
| 91 | self.log_prefix, site_name,) |
---|
| 92 | ) |
---|
| 93 | return |
---|
| 94 | elif app_folder is not None: |
---|
[5676] | 95 | # Applicants need update. Remove old instance. |
---|
[5670] | 96 | logger.warn( |
---|
[5676] | 97 | '%s: Outdated applicants folder detected at site %s.' |
---|
[5670] | 98 | 'Removing it.' % (self.log_prefix, site_name) |
---|
| 99 | ) |
---|
[5676] | 100 | del site['applicants'] |
---|
| 101 | # Add new applicants. |
---|
[5670] | 102 | logger.info( |
---|
| 103 | '%s: Updating site at %s. Installing ' |
---|
[5676] | 104 | 'applicants.' % (self.log_prefix, site_name,) |
---|
[5670] | 105 | ) |
---|
| 106 | self.setup(site, name, logger) |
---|
| 107 | return |
---|