Back to index

plone3  3.1.7
ActionIconsTool.py
Go to the documentation of this file.
00001 from Products.CMFActionIcons.ActionIconsTool import ActionIconsTool as BaseTool
00002 from Products.CMFActionIcons.permissions import View
00003 from Products.CMFCore.utils import getToolByName
00004 from Products.CMFPlone import ToolNames
00005 from AccessControl import ClassSecurityInfo
00006 from Globals import InitializeClass
00007 from Products.CMFPlone.PloneBaseTool import PloneBaseTool
00008 from Products.CMFPlone.PloneTool import _icons as iconcache
00009 
00010 def removeAICacheEntry(category, id):
00011     if (category, id) in iconcache.keys():
00012         del iconcache[(category,id)]
00013 
00014 class ActionIconsTool(PloneBaseTool, BaseTool):
00015 
00016     meta_type = ToolNames.ActionIconsTool
00017     security = ClassSecurityInfo()
00018     toolicon = 'skins/plone_images/confirm_icon.gif'
00019 
00020     __implements__ = (PloneBaseTool.__implements__, BaseTool.__implements__, )
00021 
00022     security.declareProtected(View, 'renderActionIcon')
00023     def renderActionIcon( self,
00024                           category,
00025                           action_id,
00026                           default=None,
00027                           context=None ):
00028         """ Returns the actual object for the icon.  If you
00029             pass in a path elements in default it will attempt
00030             to traverse to that path.  Otherwise it will return
00031             None
00032         """
00033         icon = self.queryActionIcon( category,
00034                                      action_id,
00035                                      default=default,
00036                                      context=context )
00037         if icon is not None:
00038             portal=getToolByName(self, 'portal_url').getPortalObject()
00039             return portal.restrictedTraverse(icon)
00040 
00041         return default
00042 
00043     #Below we need to invalidate the cache for icons.  We have to
00044     #hardocde the module dict because we do not have events, yet.
00045     def updateActionIcon( self
00046                         , category
00047                         , action_id
00048                         , icon_expr
00049                         , title=None
00050                         , priority=0
00051                         ):
00052         """ update ActionIcons and remove cache entry """
00053         BaseTool.updateActionIcon(self, category, action_id, icon_expr,
00054                                   title, priority)
00055         removeAICacheEntry(category, action_id)
00056 
00057     def removeActionIcon( self, category, action_id ):
00058         """ remove ActionIcon and remove cache entry """
00059         BaseTool.removeActionIcon(self, category, action_id)
00060         removeAICacheEntry(category, action_id)
00061 
00062     def clearActionIcons( self ):
00063         """ clear ActionIcons and cache entries """
00064         BaseTool.clearActionIcons(self)
00065         iconcache.clear()
00066 
00067     def manage_updateActionIcon( self
00068                                , category
00069                                , action_id
00070                                , icon_expr
00071                                , title
00072                                , priority
00073                                , REQUEST
00074                                ):
00075         """ update ActionIcons from ZMI and remove cache entry """
00076         BaseTool.manage_updateActionIcon( self, category, action_id, icon_expr,
00077                                           title, priority, REQUEST )
00078         removeAICacheEntry(category, action_id)
00079 
00080     def manage_removeActionIcon( self, category, action_id, REQUEST ):
00081         """ remove ActionIcons from ZMI and remove cache entry """
00082         BaseTool.manage_removeActionIcon(self, category, action_id, REQUEST)
00083         removeAICacheEntry(category, action_id)
00084 
00085 ActionIconsTool.__doc__ = BaseTool.__doc__
00086 
00087 InitializeClass(ActionIconsTool)