source: main/waeup.sirp/trunk/src/waeup/sirp/applicants/root.py @ 10009

Last change on this file since 10009 was 7652, checked in by Henrik Bettermann, 13 years ago

Do not retrieve current principal in derived logging components. This is now done by the parent Logger class.

  • Property svn:keywords set to Id
File size: 3.5 KB
RevLine 
[7192]1## $Id: root.py 7652 2012-02-15 10:51:53Z 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]19The root for applicants.
[5648]20"""
21import grok
[6121]22from hurry.query import Eq
23from hurry.query.interfaces import IQuery
24from zope.component import getUtility
[7321]25from waeup.sirp.interfaces import ISIRPPluggable
[5676]26from waeup.sirp.applicants.interfaces import IApplicantsRoot
[6578]27from waeup.sirp.utils.logger import Logger
[5648]28
[6578]29class ApplicantsRoot(grok.Container, Logger):
[6119]30    """The root of applicants-related components. It contains only
[5676]31    containers for applicants.
[5648]32    """
[5676]33    grok.implements(IApplicantsRoot)
[5670]34
[7182]35    local_roles = []
[6370]36
[6578]37    logger_name = 'waeup.sirp.${sitename}.applicants'
38    logger_filename = 'applicants.log'
[6348]39
[6475]40    def logger_info(self, target, ob_class, comment=None):
41        """Get the logger's info method.
42        """
[7652]43        self.logger.info('%s - %s - %s' % (
44                target, ob_class, comment))
[6500]45        return
[6475]46
[5676]47class ApplicantsPlugin(grok.GlobalUtility):
[7321]48    """A SIRPPlugin that creates an applicants root in portal.
[5670]49
50    This plugin should be called by a typical
51    `waeup.sirp.app.Universtiy` instance on creation time. The
52    :meth:`update` method normally can also be triggered manually over
53    the main site configuration.
54
[7321]55    Implements :class:`waeup.sirp.interfaces.ISIRPPluggable`
[5670]56    """
[5676]57    grok.name('applicants')
[7321]58    grok.implements(ISIRPPluggable)
[5676]59    log_prefix = 'ApplicantsPlugin'
[5670]60
61    def setup(self, site, name, logger):
[5676]62        """Create a new :class:`ApplicantsRoot` instance in `site`.
[5670]63        """
[5676]64        site['applicants'] = ApplicantsRoot()
[5670]65        logger.info(
[5676]66            '%s: Installed applicants root.' % (self.log_prefix,)
[5670]67            )
68        return
69
70    def update(self, site, name, logger):
[5676]71        """Update site wide ``applicants`` root.
[5670]72
[5676]73        If the site already contains a suitable ``applicants`` root,
[5670]74        leave it that way. If not create one and delete the old one if
75        appropriate.
76        """
[5676]77        app_folder = site.get('applicants', None)
[5684]78        site_name = getattr(site, '__name__', '<Unnamed Site>')
[5676]79        if IApplicantsRoot.providedBy(app_folder):
80            # Applicants up to date. Return.
[5670]81            logger.info(
82                '%s: Updating site at %s: Nothing to do.' % (
83                    self.log_prefix, site_name,)
84                )
85            return
86        elif app_folder is not None:
[5676]87            # Applicants need update. Remove old instance.
[5670]88            logger.warn(
[5676]89                '%s: Outdated applicants folder detected at site %s.'
[5670]90                'Removing it.' % (self.log_prefix, site_name)
91                    )
[5676]92            del site['applicants']
93        # Add new applicants.
[5670]94        logger.info(
95            '%s: Updating site at %s. Installing '
[5676]96            'applicants.' % (self.log_prefix, site_name,)
[5670]97            )
98        self.setup(site, name, logger)
99        return
Note: See TracBrowser for help on using the repository browser.