Back to index

plone3  3.1.7
Install.py
Go to the documentation of this file.
00001 from zope.component import getUtility
00002 from Products.CMFCore.interfaces import ISiteRoot
00003 from Products.CMFCore.utils import getToolByName
00004 from Products.CMFCore.DirectoryView import addDirectoryViews
00005 from Products.PasswordResetTool import product_globals
00006 from StringIO import StringIO
00007 import string
00008 
00009 def install(self):
00010     """Register password reset skins and add the tool"""
00011     directory_name = 'PasswordReset'
00012     
00013     out = StringIO()
00014 
00015     # Add the tool
00016     portal = getUtility(ISiteRoot)
00017     try:
00018         portal.manage_delObjects('portal_password_reset')
00019         out.write("Removed old portal_password_reset tool\n")
00020     except:
00021         pass  # we don't care if it fails
00022     portal.manage_addProduct['PasswordResetTool'].manage_addTool('Password Reset Tool', None)
00023     out.write("Adding Password Reset Tool\n")
00024 
00025     # Setup the skins
00026     skinstool = getToolByName(self, 'portal_skins')
00027     if directory_name not in skinstool.objectIds():
00028         # We need to add Filesystem Directory Views for any directories
00029         # in our skins/ directory.  These directories should already be
00030         # configured.
00031         addDirectoryViews(skinstool, 'skins', product_globals)
00032         out.write("Added %s directory view to portal_skins\n" % directory_name)
00033 
00034     # Now we need to go through the skin configurations and insert
00035     # directory_name into the configurations.  Preferably, this
00036     # should be right after where 'custom' is placed.  Otherwise, we
00037     # append it to the end.
00038     skins = skinstool.getSkinSelections()
00039     for skin in skins:
00040         path = skinstool.getSkinPath(skin)
00041         path = map(string.strip, string.split(path,','))
00042         if directory_name not in path:
00043             try: path.insert(path.index('custom')+1, directory_name)
00044             except ValueError:
00045                 path.append(directory_name)
00046                 
00047             path = string.join(path, ', ')
00048             # addSkinSelection will replace existing skins as well.
00049             skinstool.addSkinSelection(skin, path)
00050             out.write("Added %s to %s skin\n" % (directory_name, skin))
00051         else:
00052             out.write("Skipping %s skin, %s is already set up\n" % (
00053                 skin, directory_name))
00054 
00055     return out.getvalue()