Back to index

plone3  3.1.7
PropertiesTool.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
00004 #
00005 # This software is subject to the provisions of the Zope Public License,
00006 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
00007 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00008 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00009 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00010 # FOR A PARTICULAR PURPOSE.
00011 #
00012 ##############################################################################
00013 """ CMFDefault portal_properties tool.
00014 
00015 $Id: PropertiesTool.py 82567 2007-12-30 11:31:06Z jens $
00016 """
00017 
00018 from AccessControl import ClassSecurityInfo
00019 from Acquisition import aq_inner, aq_parent
00020 from Globals import InitializeClass, DTMLFile
00021 from OFS.SimpleItem import SimpleItem
00022 from Products.MailHost.interfaces import IMailHost
00023 from zope.component import getUtility
00024 from zope.component import queryUtility
00025 from zope.interface import implements
00026 
00027 from Products.CMFCore.interfaces import IPropertiesTool
00028 from Products.CMFCore.interfaces import ISiteRoot
00029 from Products.CMFCore.interfaces.portal_properties \
00030         import portal_properties as z2IPropertiesTool
00031 from Products.CMFCore.utils import registerToolInterface
00032 from Products.CMFCore.utils import UniqueObject
00033 
00034 from permissions import ManagePortal
00035 from utils import _dtmldir
00036 
00037 
00038 class PropertiesTool(UniqueObject, SimpleItem):
00039 
00040     implements(IPropertiesTool)
00041     __implements__ = (z2IPropertiesTool, )
00042 
00043     id = 'portal_properties'
00044     meta_type = 'Default Properties Tool'
00045 
00046     security = ClassSecurityInfo()
00047 
00048     manage_options = ( ({'label': 'Overview',
00049                          'action': 'manage_overview'},)
00050                      + SimpleItem.manage_options
00051                      )
00052 
00053     #
00054     #   ZMI methods
00055     #
00056     security.declareProtected(ManagePortal, 'manage_overview')
00057     manage_overview = DTMLFile( 'explainPropertiesTool', _dtmldir )
00058 
00059     #
00060     #   'portal_properties' interface methods
00061     #
00062     security.declareProtected(ManagePortal, 'editProperties')
00063     def editProperties(self, props):
00064         '''Change portal settings'''
00065         site = getUtility(ISiteRoot)
00066         site.manage_changeProperties(**props)
00067         getUtility(IMailHost).smtp_host = props['smtp_server']
00068         if hasattr(self, 'propertysheets'):
00069             ps = self.propertysheets
00070             if hasattr(ps, 'props'):
00071                 ps.props.manage_changeProperties(props)
00072 
00073     def title(self):
00074         site = queryUtility(ISiteRoot)
00075         if site is None:
00076             # fallback
00077             return aq_parent(aq_inner(self)).title
00078         return site.title
00079 
00080     def smtp_server(self):
00081         return getUtility(IMailHost).smtp_host
00082 
00083 InitializeClass(PropertiesTool)
00084 registerToolInterface('portal_properties', IPropertiesTool)