[7192] | 1 | ## $Id: root.py 13077 2015-06-19 15:36:21Z henrik $ |
---|
[5648] | 2 | ## |
---|
[6478] | 3 | ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann |
---|
[5648] | 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. |
---|
[7192] | 8 | ## |
---|
[5648] | 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. |
---|
[7192] | 13 | ## |
---|
[5648] | 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 | ## |
---|
| 18 | """ |
---|
[5676] | 19 | The root for applicants. |
---|
[5648] | 20 | """ |
---|
| 21 | import grok |
---|
[6121] | 22 | from hurry.query import Eq |
---|
| 23 | from hurry.query.interfaces import IQuery |
---|
| 24 | from zope.component import getUtility |
---|
[8388] | 25 | from zope.schema import getFields |
---|
[7819] | 26 | from waeup.kofa.interfaces import IKofaPluggable |
---|
[7811] | 27 | from waeup.kofa.applicants.interfaces import IApplicantsRoot |
---|
| 28 | from waeup.kofa.utils.logger import Logger |
---|
[8388] | 29 | from waeup.kofa.utils.helpers import attrs_to_fields |
---|
[5648] | 30 | |
---|
[6578] | 31 | class ApplicantsRoot(grok.Container, Logger): |
---|
[6119] | 32 | """The root of applicants-related components. It contains only |
---|
[5676] | 33 | containers for applicants. |
---|
[5648] | 34 | """ |
---|
[5676] | 35 | grok.implements(IApplicantsRoot) |
---|
[5670] | 36 | |
---|
[7182] | 37 | local_roles = [] |
---|
[8388] | 38 | description_dict = {} |
---|
[7811] | 39 | logger_name = 'waeup.kofa.${sitename}.applicants' |
---|
[6578] | 40 | logger_filename = 'applicants.log' |
---|
[6348] | 41 | |
---|
[8388] | 42 | ApplicantsRoot = attrs_to_fields(ApplicantsRoot) |
---|
| 43 | |
---|
[5676] | 44 | class ApplicantsPlugin(grok.GlobalUtility): |
---|
[7819] | 45 | """A KofaPlugin that creates an applicants root in portal. |
---|
[5670] | 46 | |
---|
| 47 | This plugin should be called by a typical |
---|
[7811] | 48 | `waeup.kofa.app.Universtiy` instance on creation time. The |
---|
[5670] | 49 | :meth:`update` method normally can also be triggered manually over |
---|
| 50 | the main site configuration. |
---|
| 51 | |
---|
[7819] | 52 | Implements :class:`waeup.kofa.interfaces.IKofaPluggable` |
---|
[5670] | 53 | """ |
---|
[5676] | 54 | grok.name('applicants') |
---|
[7819] | 55 | grok.implements(IKofaPluggable) |
---|
[5676] | 56 | log_prefix = 'ApplicantsPlugin' |
---|
[5670] | 57 | |
---|
| 58 | def setup(self, site, name, logger): |
---|
[5676] | 59 | """Create a new :class:`ApplicantsRoot` instance in `site`. |
---|
[5670] | 60 | """ |
---|
[5676] | 61 | site['applicants'] = ApplicantsRoot() |
---|
[5670] | 62 | logger.info( |
---|
[5676] | 63 | '%s: Installed applicants root.' % (self.log_prefix,) |
---|
[5670] | 64 | ) |
---|
| 65 | return |
---|
| 66 | |
---|
| 67 | def update(self, site, name, logger): |
---|
[5676] | 68 | """Update site wide ``applicants`` root. |
---|
[5670] | 69 | |
---|
[5676] | 70 | If the site already contains a suitable ``applicants`` root, |
---|
[5670] | 71 | leave it that way. If not create one and delete the old one if |
---|
| 72 | appropriate. |
---|
| 73 | """ |
---|
[5676] | 74 | app_folder = site.get('applicants', None) |
---|
[5684] | 75 | site_name = getattr(site, '__name__', '<Unnamed Site>') |
---|
[5676] | 76 | if IApplicantsRoot.providedBy(app_folder): |
---|
[8388] | 77 | items = getFields(IApplicantsRoot).items() |
---|
| 78 | nothing_to_do = True |
---|
[8412] | 79 | #for i in items: |
---|
| 80 | # if not hasattr(app_folder,i[0]): |
---|
| 81 | # nothing_to_do = False |
---|
| 82 | # setattr(app_folder,i[0],i[1].missing_value) |
---|
| 83 | # logger.info( |
---|
| 84 | # '%s: %s added to root.' % (self.log_prefix,i[0])) |
---|
[8773] | 85 | # can be removed after upgrading futminna |
---|
[8412] | 86 | #if not hasattr(app_folder, 'description_dict'): |
---|
| 87 | # nothing_to_do = False |
---|
| 88 | # setattr(app_folder,'description_dict',{}) |
---|
| 89 | # logger.info( |
---|
| 90 | # '%s: description_dict added to root.' % self.log_prefix) |
---|
[8388] | 91 | if nothing_to_do: |
---|
| 92 | logger.info( |
---|
| 93 | '%s: Updating site at %s: Nothing to do.' % ( |
---|
| 94 | self.log_prefix, site_name,) |
---|
| 95 | ) |
---|
[5670] | 96 | return |
---|
| 97 | elif app_folder is not None: |
---|
[5676] | 98 | # Applicants need update. Remove old instance. |
---|
[5670] | 99 | logger.warn( |
---|
[5676] | 100 | '%s: Outdated applicants folder detected at site %s.' |
---|
[5670] | 101 | 'Removing it.' % (self.log_prefix, site_name) |
---|
| 102 | ) |
---|
[5676] | 103 | del site['applicants'] |
---|
| 104 | # Add new applicants. |
---|
[5670] | 105 | logger.info( |
---|
| 106 | '%s: Updating site at %s. Installing ' |
---|
[5676] | 107 | 'applicants.' % (self.log_prefix, site_name,) |
---|
[5670] | 108 | ) |
---|
| 109 | self.setup(site, name, logger) |
---|
| 110 | return |
---|