source: WAeUP_SRP/trunk/patches/PatchRenderActionIcon.py @ 17722

Last change on this file since 17722 was 3673, checked in by jens, 16 years ago
  • unclutter package by moving all patch files into a dedicated subfolder and importing it.
File size: 1.4 KB
Line 
1from Products.CMFCore.utils import getToolByName
2
3ACTIONICON_RAMCACHE_ID = 'actioncons'
4IMG_TAG = '<img src="%s" width="%s" height="%s" alt="%s" />'
5
6def renderActionIcon(self, category=None, action_id=None,
7                     base_url='', alt=''):
8    """Renders the action's icon"""
9
10    if category is None or action_id is None:
11        return None
12
13    aitool = getToolByName(self, 'portal_actionicons', None)
14    if aitool is None:
15        return None
16
17    cache = self.getCache(ACTIONICON_RAMCACHE_ID)
18    # compute the cache index
19    index = (action_id, category, base_url, alt)
20
21    img_tag = cache.getEntry(index)
22    # the icon is not in the cache
23    if img_tag is None:
24        icon_path = aitool.queryActionIcon(category=category,
25            action_id=action_id)
26        if not icon_path:
27            return
28
29
30
31        # fall back to the icon path specified in CMFActionIcons
32        img = self.unrestrictedTraverse(icon_path, default=None)
33        if img is None:
34            return None
35        img_tag = IMG_TAG % (icon_path,
36                             getattr(img, 'width', 0),
37                             getattr(img, 'height', 0),
38                             alt)
39        if cache is not None:
40            cache.setEntry(index, img_tag)
41    return img_tag
42
43from Products.CPSPortlets.PortletsTool import PortletsTool
44PortletsTool.renderActionIcon = renderActionIcon
Note: See TracBrowser for help on using the repository browser.