Back to index

plone3  3.1.7
atct.py
Go to the documentation of this file.
00001 #  ATContentTypes http://plone.org/products/atcontenttypes/
00002 #  Archetypes reimplementation of the CMF core types
00003 #  Copyright (c) 2003-2006 AT Content Types development team
00004 #
00005 #  This program is free software; you can redistribute it and/or modify
00006 #  it under the terms of the GNU General Public License as published by
00007 #  the Free Software Foundation; either version 2 of the License, or
00008 #  (at your option) any later version.
00009 #
00010 #  This program is distributed in the hope that it will be useful,
00011 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 #  GNU General Public License for more details.
00014 #
00015 #  You should have received a copy of the GNU General Public License
00016 #  along with this program; if not, write to the Free Software
00017 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 #
00019 """
00020 """
00021 __author__  = 'Christian Heimes <tiran@cheimes.de>'
00022 
00023 import logging
00024 from cStringIO import StringIO
00025 from zope.interface import implements
00026 
00027 import AccessControl.Owned
00028 from AccessControl import ClassSecurityInfo
00029 from Globals import InitializeClass
00030 from OFS.SimpleItem import SimpleItem
00031 from OFS.PropertyManager import PropertyManager
00032 from ZODB.POSException import ConflictError
00033 
00034 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
00035 
00036 from Products.CMFCore.utils import registerToolInterface
00037 from Products.CMFCore.utils import UniqueObject
00038 from Products.CMFCore.utils import getToolByName
00039 from Products.CMFCore.permissions import ManagePortal
00040 
00041 from Products.ATContentTypes.interfaces import IImageContent
00042 from Products.ATContentTypes.interfaces import IATCTTool as z2IATCTTool
00043 from Products.ATContentTypes.interface import IATCTTool
00044 from Products.ATContentTypes.config import TOOLNAME
00045 from Products.ATContentTypes.config import WWW_DIR
00046 from Products.ATContentTypes.tool.topic import ATTopicsTool
00047 
00048 LOG = logging.getLogger('ATCT')
00049 
00050 def log(message,summary='',severity=logging.DEBUG):
00051     LOG.log(severity, 'ATCT: %s \n%s', summary, message)
00052 
00053 class ATCTTool(UniqueObject, SimpleItem, PropertyManager, ATTopicsTool):
00054     """ATContentTypes tool
00055     """
00056     security = ClassSecurityInfo()
00057 
00058     id = TOOLNAME
00059     meta_type= 'ATCT Tool'
00060     title = 'ATContentTypes Tool'
00061 
00062     __implements__ = (SimpleItem.__implements__, z2IATCTTool,
00063                       ATTopicsTool.__implements__)
00064 
00065     implements(IATCTTool)
00066 
00067     manage_options =  (
00068             {'label' : 'Overview', 'action' : 'manage_overview'},
00069             {'label' : 'Image scales', 'action' : 'manage_imageScales'}
00070         ) + PropertyManager.manage_options + \
00071             AccessControl.Owned.Owned.manage_options
00072 
00073     # properties
00074 
00075     _properties = PropertyManager._properties + (
00076         {'id' : 'image_types', 'type' : 'multiple selection',
00077          'mode' : 'w', 'select_variable' : 'listContentTypes'},
00078         {'id' : 'folder_types', 'type' : 'multiple selection',
00079          'mode' : 'w', 'select_variable' : 'listContentTypes'},
00080         {'id' : 'album_batch_size', 'type' : 'int', 'mode' : 'w'},
00081         {'id' : 'album_image_scale', 'type' : 'string', 'mode' : 'w'},
00082         {'id' : 'single_image_scale', 'type' : 'string', 'mode' : 'w'},
00083         )
00084 
00085     # templates
00086 
00087     security.declareProtected(ManagePortal, 'manage_imageScales')
00088     manage_imageScales = PageTemplateFile('imageScales', WWW_DIR)
00089 
00090     security.declareProtected(ManagePortal, 'manage_overview')
00091     manage_overview = PageTemplateFile('overview', WWW_DIR)
00092 
00093     def om_icons(self):
00094         icons = ({'path':'misc_/ATContentTypes/tool.gif',
00095                   'alt':self.meta_type,
00096                   'title':self.meta_type},)
00097         return icons
00098 
00099     # image scales
00100 
00101     security.declareProtected(ManagePortal, 'recreateImageScales')
00102     def recreateImageScales(self, portal_type=None):
00103         """Recreates AT Image scales (doesn't remove unused!)
00104         """
00105         if portal_type is None:
00106             portal_type = tuple(self.image_types)
00107         out = StringIO()
00108         print >> out, "Updating AT Image scales"
00109         catalog = getToolByName(self, 'portal_catalog')
00110         brains = catalog(portal_type = portal_type,
00111                          portal_type_operator = 'or')
00112         for brain in brains:
00113             obj = brain.getObject()
00114             if obj is None:
00115                 continue
00116             if not IImageContent.isImplementedBy(obj):
00117                 continue
00118             try:
00119                 state = obj._p_changed
00120             except (ConflictError, KeyboardInterrupt):
00121                 raise
00122             except:
00123                 state = 0
00124 
00125             field = obj.getField('image')
00126             if field is not None:
00127                 print >> out, 'Updating %s' % obj.absolute_url(1)
00128                 field.removeScales(obj)
00129                 field.createScales(obj)
00130 
00131             if state is None:
00132                 obj._p_deactivate()
00133 
00134         print >> out, "Updated AT Image scales"
00135         return out.getvalue()
00136 
00137     security.declareProtected(ManagePortal, 'listContentTypes')
00138     def listContentTypes(self):
00139         """List all content types. Used for image/folder_types property.
00140         """
00141         ttool = getToolByName(self, 'portal_types')
00142         return ttool.listContentTypes()
00143 
00144 InitializeClass(ATCTTool)
00145 registerToolInterface('portal_atct', IATCTTool)