Back to index

plone3  3.1.7
subscriber.py
Go to the documentation of this file.
00001 ##########################################################
00002 #
00003 # Licensed under the terms of the GNU Public License
00004 # (see docs/LICENSE.GPL)
00005 #
00006 # Copyright (c) 2005:
00007 #   - The Open Planning Project (http://www.openplans.org/)
00008 #   - Whit Morriss <whit at www.openplans.org>
00009 #   - and contributors
00010 #
00011 ##########################################################
00012 from wicked import config, utils
00013 from zope.app.container.interfaces import IObjectRemovedEvent, IObjectAddedEvent
00014 from wicked.interfaces import IAmWicked, IAmWickedField, IUID
00015 from Products.Archetypes.interfaces import ISchema
00016 
00017 # @@ these a very at specific
00018 
00019 def at_handle_target_deletion(ref, event):
00020     """
00021     Invalidate any pointer before object deletion
00022     """
00023     target = ref.getTargetObject()
00024     for field in ISchema(target).fields():
00025         if IAmWickedField.providedBy(field):
00026             wicked = utils.getWicked(field, target)
00027             wicked.unlink(ref.sourceUID)
00028             break
00029 
00030 def at_handle_target_moved(obj, event):
00031     """
00032     when a target of a link is moved, or renamed we need to notify any
00033     objects that may be caching pointers
00034     """
00035     #@@ add more tests
00036     if IObjectRemovedEvent.providedBy(event):
00037         return
00038     
00039     refs=obj.getRefs(relationship=config.BACKLINK_RELATIONSHIP)
00040     path = '/'.join(obj.getPhysicalPath())
00041     for target in refs:
00042         for field in ISchema(target).fields():
00043             wicked = utils.getWicked(field, target)
00044             uid = IUID(obj)
00045             data = dict(path=path,
00046                         icon=obj.getIcon(),
00047                         uid=uid)
00048             wicked.cache.reset(uid, [data])
00049 
00050