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

Last change on this file since 5747 was 5684, checked in by uli, 14 years ago

Use a better understandable string when reporting applicant plugin actions on unnamed sites.

File size: 3.8 KB
Line 
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"""
23The root for applicants.
24"""
25import grok
26from waeup.sirp.interfaces import IWAeUPSIRPPluggable
27from waeup.sirp.applicants.interfaces import IApplicantsRoot
28
29class ApplicantsRoot(grok.Container):
30    """The root of applicants-related components. It contains primarily
31    containers for applicants.
32    """
33    grok.implements(IApplicantsRoot)
34
35    def addApplicantsContainer(self, container, name=None):
36        """Add an applicants container.
37
38        Adds an applicants container that implements `interface`
39        under the name `name`.
40
41        `container`
42          the container instance to be added. Should
43          implement :class:`IApplicantsContainer`.
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
48          new container will contain student applicants for a
49          certain screening type (``pume``) and of the year 2011.
50
51        """
52        self[name] = container
53        return
54
55class ApplicantsPlugin(grok.GlobalUtility):
56    """A WAeUPSIRPPlugin that creates an applicants root in portal.
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    """
65    grok.name('applicants')
66    grok.implements(IWAeUPSIRPPluggable)
67    log_prefix = 'ApplicantsPlugin'
68
69    def setup(self, site, name, logger):
70        """Create a new :class:`ApplicantsRoot` instance in `site`.
71        """
72        site['applicants'] = ApplicantsRoot()
73        logger.info(
74            '%s: Installed applicants root.' % (self.log_prefix,)
75            )
76        return
77
78    def update(self, site, name, logger):
79        """Update site wide ``applicants`` root.
80
81        If the site already contains a suitable ``applicants`` root,
82        leave it that way. If not create one and delete the old one if
83        appropriate.
84        """
85        app_folder = site.get('applicants', None)
86        site_name = getattr(site, '__name__', '<Unnamed Site>')
87        if IApplicantsRoot.providedBy(app_folder):
88            # Applicants up to date. Return.
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:
95            # Applicants need update. Remove old instance.
96            logger.warn(
97                '%s: Outdated applicants folder detected at site %s.'
98                'Removing it.' % (self.log_prefix, site_name)
99                    )
100            del site['applicants']
101        # Add new applicants.
102        logger.info(
103            '%s: Updating site at %s. Installing '
104            'applicants.' % (self.log_prefix, site_name,)
105            )
106        self.setup(site, name, logger)
107        return
Note: See TracBrowser for help on using the repository browser.