Back to index

plone3  3.1.7
final_two51.py
Go to the documentation of this file.
00001 from Products.CMFCore.ActionInformation import Action
00002 from Products.CMFCore.permissions import DeleteObjects
00003 from Products.CMFCore.utils import getToolByName
00004 from Products.CMFPlone.UnicodeSplitter import Splitter, CaseNormalizer
00005 from Products.CMFPlone.migrations.v3_0.alphas import migrateOldActions
00006 from Products.CMFPlone.migrations.v3_0.alphas import enableZope3Site
00007 from Products.CMFPlone.migrations.v3_0.alphas import registerToolsAsUtilities
00008 
00009 
00010 def final_two51(portal):
00011     """2.5-final -> 2.5.1
00012     """
00013     out = []
00014 
00015     # Make the portal a Zope3 site
00016     enableZope3Site(portal, out)
00017 
00018     # register some tools as utilities
00019     registerToolsAsUtilities(portal, out)
00020 
00021     removePloneCssFromRR(portal, out)
00022 
00023     # add event_registration.js
00024     addEventRegistrationJS(portal, out)
00025 
00026     # Repair plone_lexicon pipeline
00027     fixupPloneLexicon(portal, out)
00028 
00029     # We need to migrate all existing actions to new-style actions first
00030     migrateOldActions(portal, out)
00031     # Make object delete action use confirmation form
00032     fixObjDeleteAction(portal, out)
00033 
00034     # Required for #5569 (is_folderish needs reindexing) and #5231 (all text
00035     # indices need to be reindexed so they are split properly)
00036     migtool = getToolByName(portal, 'portal_migration')
00037     migtool._needRecatalog = True
00038 
00039     return out
00040 
00041 
00042 def removePloneCssFromRR(portal, out):
00043     """Removes the redundant, deprecated, and failing plone.css from portal_css.
00044        It is a python script now and just calls portal_css itself."""
00045     css_reg = getToolByName(portal, 'portal_css', None)
00046     if css_reg is not None:
00047         stylesheet_ids = css_reg.getResourceIds()
00048         if 'plone.css' in stylesheet_ids:
00049             css_reg.unregisterResource('plone.css')
00050             out.append('Unregistered deprecated plone.css')
00051 
00052 
00053 def addEventRegistrationJS(portal, out):
00054     """Add event-registration.js to ResourceRegistries.
00055     """
00056     jsreg = getToolByName(portal, 'portal_javascripts', None)
00057     script = 'event-registration.js'
00058     if jsreg is not None:
00059         script_ids = jsreg.getResourceIds()
00060         # Failsafe: first make sure the stylesheet doesn't exist in the list
00061         if script not in script_ids:
00062             jsreg.registerScript(script)
00063             # put it at the top of the stack
00064             jsreg.moveResourceToTop(script)
00065             out.append("Added " + script + " to portal_javascipt")
00066 
00067 
00068 def fixupPloneLexicon(portal, out):
00069     """Updates the plone_lexicon pipeline with the new splitter
00070        and case normalizer.
00071     """
00072     catalog = getToolByName(portal, 'portal_catalog', None)
00073     if catalog is not None:
00074         if 'plone_lexicon' in catalog.objectIds():
00075             lexicon = catalog.plone_lexicon
00076             pipeline = list(lexicon._pipeline)
00077             if len(pipeline) >= 2:
00078                 if (not isinstance(pipeline[0], Splitter) or
00079                     not isinstance(pipeline[1], CaseNormalizer)):
00080                     pipeline[0] = Splitter()
00081                     pipeline[1] = CaseNormalizer()
00082                     lexicon._pipeline = tuple(pipeline)
00083                     # Clear the lexicon
00084                     from BTrees.OIBTree import OIBTree
00085                     from BTrees.IOBTree import IOBTree
00086                     from BTrees.Length import Length
00087                     lexicon._wids = OIBTree()
00088                     lexicon._words = IOBTree()
00089                     lexicon.length = Length()
00090                     out.append('Updated plone_lexicon pipeline.')
00091 
00092 
00093 def fixObjDeleteAction(portal, out):
00094     """Make the delete action use the new confirmation form
00095     """
00096     delete = Action('delete',
00097         title='Delete',
00098         i18n_domain='plone',
00099         url_expr='string:${globals_view/getCurrentObjectUrl}/delete_confirmation',
00100         available_expr='python:checkPermission("Delete objects", globals_view.getParentObject()) and not globals_view.isPortalOrPortalDefaultPage()',
00101         permissions=(DeleteObjects,),
00102         visible=True)
00103 
00104     actionsTool = getToolByName(portal, 'portal_actions', None)
00105     if actionsTool is not None:
00106         category = actionsTool.object_buttons
00107         for action in category.objectIds():
00108             # if action exists, remove and re-add
00109             if action == 'delete':
00110                 category._delObject('delete')
00111                 break
00112 
00113         category['delete'] = delete
00114         category.moveObjectsToBottom(('delete',))
00115         category.moveObjectsUp(('delete',))
00116         out.append("Added/modified delete object_buttons action.")