Back to index

plone3  3.1.7
setuphandlers.py
Go to the documentation of this file.
00001 """
00002 PortalTransforms setup handlers.
00003 """
00004 
00005 from StringIO import StringIO
00006 from Products.CMFCore.utils import getToolByName
00007 
00008 
00009 def correctMapping(out, portal):
00010     pt = getToolByName(portal, 'portal_transforms')
00011     pt_ids = pt.objectIds()
00012 
00013     for m_in, m_out_dict in pt._mtmap.items():
00014         for m_out, transforms in m_out_dict.items():
00015             for transform in transforms:
00016                 if transform.id not in pt_ids:
00017                     #error, mapped transform is no object in portal_transforms. correct it!
00018                     print >>out, "have to unmap transform (%s) cause its not in portal_transforms ..." % transform.id
00019                     try:
00020                         pt._unmapTransform(transform)
00021                     except:
00022                         raise
00023                     else:
00024                         print >>out, "...ok"
00025 
00026 def updateSafeHtml(out, portal):
00027     print >>out, 'Update safe_html...'
00028     safe_html_id = 'safe_html'
00029     safe_html_module = "Products.PortalTransforms.transforms.safe_html"
00030     pt = getToolByName(portal, 'portal_transforms')
00031     for id in pt.objectIds():
00032         transform = getattr(pt, id)
00033         if transform.id == safe_html_id and transform.module == safe_html_module:
00034             try:
00035                 disable_transform = transform.get_parameter_value('disable_transform')
00036             except KeyError:
00037                 print >>out, '  replace safe_html (%s, %s) ...' % (transform.name(), transform.module)
00038                 try:
00039                     pt.unregisterTransform(id)
00040                     pt.manage_addTransform(id, safe_html_module)
00041                 except:
00042                     raise
00043                 else:
00044                     print >>out, '  ...done'
00045     
00046     print >>out, '...done'
00047 
00048 
00049 def installPortalTransforms(portal):
00050     out = StringIO()
00051 
00052     updateSafeHtml(out, portal)
00053 
00054     correctMapping(out, portal)
00055 
00056 def setupPortalTransforms(context):
00057     """
00058     Setup PortalTransforms step.
00059     """
00060     # Only run step if a flag file is present (e.g. not an extension profile)
00061     if context.readDataFile('portal-transforms-various.txt') is None:
00062         return
00063     out = []
00064     site = context.getSite()
00065     installPortalTransforms(site)
00066