## ## container.py ## Login : ## Started on Tue Jun 7 12:02:19 2011 Uli Fouquet ## $Id$ ## ## Copyright (C) 2011 Uli Fouquet ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ## """ Components for storing site images (passport photographs, etc.) """ import grok from waeup.sirp.interfaces import IWAeUPSIRPPluggable, IImagesContainer class ImagesContainer(grok.Container): grok.implements(IImagesContainer) class ImagesContainerPlugin(grok.GlobalUtility): """A WAeUPSIRPPlugin that creates an images container in portal. This plugin should be called by a typical `waeup.sirp.app.Universtiy` instance on creation time. The :meth:`update` method normally can also be triggered manually over the main site configuration. Implements :class:`waeup.sirp.interfaces.IWAeUPSIRPPluggable` """ grok.name('images') grok.implements(IWAeUPSIRPPluggable) log_prefix = 'ImagesPlugin' def setup(self, site, name, logger): """Create a new :class:`ImagesContainer` instance in `site`. """ site['images'] = ImagesContainer() logger.info( '%s: Installed images container.' % (self.log_prefix,) ) return def update(self, site, name, logger): """Update site wide ``images`` container. If the site already contains a suitable ``images`` container, leave it that way. If not create one and delete the old one if appropriate. """ images_folder = site.get('images', None) site_name = getattr(site, '__name__', '') if IImagesContainer.providedBy(images_folder): # Applicants up to date. Return. logger.info( '%s: Updating site at %s: Nothing to do.' % ( self.log_prefix, site_name,) ) return elif images_folder is not None: # Images need update. Remove old instance. logger.warn( '%s: Outdated images folder detected at site %s.' 'Removing it.' % (self.log_prefix, site_name) ) del site['images'] # Add new images container. logger.info( '%s: Updating site at %s. Installing ' 'images container.' % (self.log_prefix, site_name,) ) self.setup(site, name, logger) return