Back to index

plone3  3.1.7
PropertiesTool.py
Go to the documentation of this file.
00001 from Acquisition import aq_parent, aq_inner
00002 from Products.CMFCore.permissions import ManagePortal
00003 from Products.CMFDefault.PropertiesTool import PropertiesTool as BaseTool
00004 from Products.CMFPlone import ToolNames
00005 
00006 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
00007 from OFS.Folder import Folder
00008 from Globals import InitializeClass
00009 from zope.interface import implements
00010 
00011 from OFS.PropertyManager import PropertyManager
00012 from OFS.SimpleItem import SimpleItem
00013 from AccessControl import ClassSecurityInfo
00014 from Products.CMFPlone.PloneBaseTool import PloneBaseTool
00015 from Products.CMFPlone.interfaces import IPropertiesTool, ISimpleItemWithProperties
00016 from Products.CMFPlone.interfaces.PropertiesTool import IPropertiesTool as z2IPropertiesTool
00017 
00018 class PropertiesTool(PloneBaseTool, Folder, BaseTool):
00019 
00020     id = BaseTool.id
00021     toolicon = 'skins/plone_images/topic_icon.gif'
00022 
00023     meta_type = ToolNames.PropertiesTool
00024     meta_types = ((
00025         {'name' : 'Plone Property Sheet',
00026          'action' : 'manage_addPropertySheetForm'
00027          },
00028         ))
00029 
00030     implements(IPropertiesTool)
00031     __implements__ = ((z2IPropertiesTool,) +
00032                       (Folder.__implements__, ))
00033 
00034     manage_options = ((Folder.manage_options[0],) +
00035                         BaseTool.manage_options)
00036 
00037     manage_addPropertySheetForm = PageTemplateFile('www/addPropertySheet',
00038                                                    globals())
00039 
00040     security = ClassSecurityInfo()
00041 
00042     def all_meta_types(self, interfaces=None):
00043         return self.meta_types
00044 
00045     def title(self):
00046         """ Return BaseTool title
00047         """
00048         return BaseTool.title(self)
00049 
00050     def addPropertySheet(self, id, title='', propertysheet=None):
00051         """ Add a new PropertySheet
00052         """
00053         o = SimpleItemWithProperties(id, title)
00054 
00055         # copy the propertysheet values onto the new instance
00056         if propertysheet is not None:
00057             if not hasattr(propertysheet, 'propertyIds'):
00058                 raise TypeError, 'propertysheet needs to be a PropertyManager'
00059 
00060             for property in propertysheet.propertyMap():
00061                 pid=property.get('id')
00062                 ptype=property.get('type')
00063                 pvalue=propertysheet.getProperty(pid)
00064                 if not hasattr(o, pid):
00065                     o._setProperty(pid, pvalue, ptype)
00066 
00067         self._setObject(id, o)
00068 
00069 
00070     def manage_addPropertySheet(self, id, title='',
00071                                 propertysheet=None, REQUEST=None):
00072         """ Add a instance of a Property Sheet if handed a
00073         propertysheet put the properties into new propertysheet.
00074         """
00075         self.addPropertySheet(id, title, propertysheet)
00076 
00077         if REQUEST is not None:
00078             return self.manage_main()
00079 
00080     #
00081     #   'portal_properties' interface methods
00082     #
00083     security.declareProtected(ManagePortal, 'editProperties')
00084     def editProperties(self, props):
00085         """Change portal settings
00086         """
00087         aq_parent(aq_inner(self)).manage_changeProperties(props)
00088         if hasattr(self, 'propertysheets'):
00089             ps = self.propertysheets
00090             if hasattr(ps, 'props'):
00091                 ps.props.manage_changeProperties(props)
00092 
00093 
00094 PropertiesTool.__doc__ = BaseTool.__doc__
00095 
00096 InitializeClass(PropertiesTool)
00097 
00098 
00099 class SimpleItemWithProperties (PropertyManager, SimpleItem):
00100     """
00101     A common base class for objects with configurable
00102     properties in a fixed schema.
00103     """
00104 
00105     implements(ISimpleItemWithProperties)
00106 
00107     def __init__(self, id, title=''):
00108         self.id = id
00109         self.title = title
00110 
00111     meta_type = 'Plone Property Sheet'
00112 
00113     manage_options = ( PropertyManager.manage_options
00114                      + SimpleItem.manage_options)
00115 
00116 InitializeClass(SimpleItemWithProperties)