[6293] | 1 | ## |
---|
| 2 | ## container.py |
---|
| 3 | ## Login : <uli@pu.smp.net> |
---|
| 4 | ## Started on Tue Jun 7 12:02:19 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 | """ |
---|
| 23 | Components for storing site images (passport photographs, etc.) |
---|
| 24 | """ |
---|
| 25 | import grok |
---|
| 26 | from waeup.sirp.interfaces import IWAeUPSIRPPluggable, IImagesContainer |
---|
| 27 | |
---|
| 28 | class ImagesContainer(grok.Container): |
---|
| 29 | grok.implements(IImagesContainer) |
---|
| 30 | |
---|
| 31 | |
---|
| 32 | class ImagesContainerPlugin(grok.GlobalUtility): |
---|
| 33 | """A WAeUPSIRPPlugin that creates an images container in portal. |
---|
| 34 | |
---|
| 35 | This plugin should be called by a typical |
---|
| 36 | `waeup.sirp.app.Universtiy` instance on creation time. The |
---|
| 37 | :meth:`update` method normally can also be triggered manually over |
---|
| 38 | the main site configuration. |
---|
| 39 | |
---|
| 40 | Implements :class:`waeup.sirp.interfaces.IWAeUPSIRPPluggable` |
---|
| 41 | """ |
---|
| 42 | grok.name('images') |
---|
| 43 | grok.implements(IWAeUPSIRPPluggable) |
---|
| 44 | log_prefix = 'ImagesPlugin' |
---|
| 45 | |
---|
| 46 | def setup(self, site, name, logger): |
---|
| 47 | """Create a new :class:`ImagesContainer` instance in `site`. |
---|
| 48 | """ |
---|
| 49 | site['images'] = ImagesContainer() |
---|
| 50 | logger.info( |
---|
| 51 | '%s: Installed images container.' % (self.log_prefix,) |
---|
| 52 | ) |
---|
| 53 | return |
---|
| 54 | |
---|
| 55 | def update(self, site, name, logger): |
---|
| 56 | """Update site wide ``images`` container. |
---|
| 57 | |
---|
| 58 | If the site already contains a suitable ``images`` container, |
---|
| 59 | leave it that way. If not create one and delete the old one if |
---|
| 60 | appropriate. |
---|
| 61 | """ |
---|
| 62 | images_folder = site.get('images', None) |
---|
| 63 | site_name = getattr(site, '__name__', '<Unnamed Site>') |
---|
| 64 | if IImagesContainer.providedBy(images_folder): |
---|
| 65 | # Applicants up to date. Return. |
---|
| 66 | logger.info( |
---|
| 67 | '%s: Updating site at %s: Nothing to do.' % ( |
---|
| 68 | self.log_prefix, site_name,) |
---|
| 69 | ) |
---|
| 70 | return |
---|
| 71 | elif images_folder is not None: |
---|
| 72 | # Images need update. Remove old instance. |
---|
| 73 | logger.warn( |
---|
| 74 | '%s: Outdated images folder detected at site %s.' |
---|
| 75 | 'Removing it.' % (self.log_prefix, site_name) |
---|
| 76 | ) |
---|
| 77 | del site['images'] |
---|
| 78 | # Add new images container. |
---|
| 79 | logger.info( |
---|
| 80 | '%s: Updating site at %s. Installing ' |
---|
| 81 | 'images container.' % (self.log_prefix, site_name,) |
---|
| 82 | ) |
---|
| 83 | self.setup(site, name, logger) |
---|
| 84 | return |
---|
| 85 | |
---|
| 86 | |
---|