Back to index

plone3  3.1.7
subscribers.py
Go to the documentation of this file.
00001 from zope.component import queryUtility
00002 from Products.CMFCore.utils import getToolByName
00003 from plone.app.redirector.interfaces import IRedirectionStorage
00004 
00005 from Acquisition import aq_base
00006 
00007 def objectMoved(obj, event):
00008     """Tell the redirection storage that an object moved
00009     """
00010 
00011     # Unfortunately, IObjectMoved is a rather generic event...
00012     if event.oldParent is not None and event.newParent is not None and event.oldName is not None:
00013         storage = queryUtility(IRedirectionStorage)
00014         if storage is not None:
00015             old_path = "%s/%s" % ('/'.join(event.oldParent.getPhysicalPath()), event.oldName,)
00016             new_path = '/'.join(obj.getPhysicalPath())
00017 
00018             # This event gets redispatched to children, and we should keep track of them as well
00019             # In this case, event.object is not the same as obj, and the old_path should actually
00020             # include obj.id
00021 
00022             if aq_base(event.object) is not aq_base(obj):
00023                 new_path_of_moved = '/'.join(event.object.getPhysicalPath())
00024                 old_path = old_path + new_path[len(new_path_of_moved):]
00025 
00026             # XXX: Special case - don't remember anything happening inside portal_factory
00027             if '/portal_factory/' in old_path:
00028                 return
00029 
00030             # Special case: don't remember object when it was just created...
00031             putils = getToolByName(obj, 'plone_utils')
00032             if putils is not None and putils.isIDAutoGenerated(event.oldName):
00033                 request = getattr(obj, 'REQUEST', None)
00034                 if request is not None:
00035                     url = request['ACTUAL_URL'].split('/')
00036                     if 'portal_factory' in url and event.oldName in url:
00037                         return
00038 
00039             storage.add(old_path, new_path)
00040 
00041 def objectRemoved(obj, event):
00042     """Tell the redirection storage that the object was removed
00043     """
00044     storage = queryUtility(IRedirectionStorage)
00045     if storage is not None:
00046         path = '/'.join(obj.getPhysicalPath())
00047         storage.destroy(path)