source: main/waeup.kofa/trunk/src/waeup/kofa/applicants/root.py @ 13132

Last change on this file since 13132 was 13077, checked in by Henrik Bettermann, 9 years ago

More adjustments for a proper documentation.

  • Property svn:keywords set to Id
File size: 4.1 KB
Line 
1## $Id: root.py 13077 2015-06-19 15:36:21Z 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##
18"""
19The root for applicants.
20"""
21import grok
22from hurry.query import Eq
23from hurry.query.interfaces import IQuery
24from zope.component import getUtility
25from zope.schema import getFields
26from waeup.kofa.interfaces import IKofaPluggable
27from waeup.kofa.applicants.interfaces import IApplicantsRoot
28from waeup.kofa.utils.logger import Logger
29from waeup.kofa.utils.helpers import attrs_to_fields
30
31class ApplicantsRoot(grok.Container, Logger):
32    """The root of applicants-related components. It contains only
33    containers for applicants.
34    """
35    grok.implements(IApplicantsRoot)
36
37    local_roles = []
38    description_dict = {}
39    logger_name = 'waeup.kofa.${sitename}.applicants'
40    logger_filename = 'applicants.log'
41
42ApplicantsRoot = attrs_to_fields(ApplicantsRoot)
43
44class ApplicantsPlugin(grok.GlobalUtility):
45    """A KofaPlugin that creates an applicants root in portal.
46
47    This plugin should be called by a typical
48    `waeup.kofa.app.Universtiy` instance on creation time. The
49    :meth:`update` method normally can also be triggered manually over
50    the main site configuration.
51
52    Implements :class:`waeup.kofa.interfaces.IKofaPluggable`
53    """
54    grok.name('applicants')
55    grok.implements(IKofaPluggable)
56    log_prefix = 'ApplicantsPlugin'
57
58    def setup(self, site, name, logger):
59        """Create a new :class:`ApplicantsRoot` instance in `site`.
60        """
61        site['applicants'] = ApplicantsRoot()
62        logger.info(
63            '%s: Installed applicants root.' % (self.log_prefix,)
64            )
65        return
66
67    def update(self, site, name, logger):
68        """Update site wide ``applicants`` root.
69
70        If the site already contains a suitable ``applicants`` root,
71        leave it that way. If not create one and delete the old one if
72        appropriate.
73        """
74        app_folder = site.get('applicants', None)
75        site_name = getattr(site, '__name__', '<Unnamed Site>')
76        if IApplicantsRoot.providedBy(app_folder):
77            items = getFields(IApplicantsRoot).items()
78            nothing_to_do = True
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]))
85            # can be removed after upgrading futminna
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)
91            if nothing_to_do:
92                logger.info(
93                    '%s: Updating site at %s: Nothing to do.' % (
94                        self.log_prefix, site_name,)
95                    )
96            return
97        elif app_folder is not None:
98            # Applicants need update. Remove old instance.
99            logger.warn(
100                '%s: Outdated applicants folder detected at site %s.'
101                'Removing it.' % (self.log_prefix, site_name)
102                    )
103            del site['applicants']
104        # Add new applicants.
105        logger.info(
106            '%s: Updating site at %s. Installing '
107            'applicants.' % (self.log_prefix, site_name,)
108            )
109        self.setup(site, name, logger)
110        return
Note: See TracBrowser for help on using the repository browser.