source: main/waeup.sirp/branches/henrik-bootstrap/src/waeup/sirp/applicants/root.py @ 11107

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

Also application_exists is outdated and no longer used.

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