source: products/qPloneTabs/tags/0.2.1/utils.py @ 1591

Last change on this file since 1591 was 1, checked in by myroslav, 18 years ago

Building directory structure

  • Property svn:eol-style set to native
File size: 1.7 KB
Line 
1"""
2   Utility functions for portal_tab actions modifications.
3"""
4from Products.CMFCore.Expression import Expression
5from Products.CMFCore.utils import getToolByName
6
7def getPortalTabs(self):
8    """ Return all portal actions with 'portal_tabs' category """
9    return filter(lambda a: a.category == 'portal_tabs', getToolByName(self, 'portal_actions')._cloneActions())
10
11def editAction(self, num, name, id, action='', condition=''):
12    """ Function for editing given action """
13    actions = getToolByName(self, 'portal_actions')._actions
14    tabs = filter(lambda a: a.category == 'portal_tabs', actions)
15    tab = tabs[int(num)]
16    if id: tab.id = id
17    if name: tab.title = name
18    if isinstance(condition, basestring): tab.condition = Expression(condition)
19    if isinstance(action, basestring): tab.setActionExpression(Expression(action))
20    return True
21
22def reorderActions(self, idxs):
23    """ Reorder portal_tabs actions in given order """
24    idxs = list(map(int,idxs))
25    portal_actions = getToolByName(self, 'portal_actions')
26    actions = portal_actions._cloneActions()
27    tabs = [[action, actions.index(action)] for action in actions if action.category == 'portal_tabs']
28    for idx in range(len(idxs)):
29        actions[tabs[idx][1]] = tabs[idxs[idx]][0]
30    portal_actions._actions = tuple(actions)
31    return idxs
32
33def deleteAction(self, idx, id):
34    """ Delete portal_tabs action with given index """
35    portal_actions = getToolByName(self, 'portal_actions')
36    actions = portal_actions._cloneActions()
37    tabs = filter(lambda a: a.category == 'portal_tabs', actions)
38    if tabs[int(idx)].id == id:
39        portal_actions.deleteActions([actions.index(tabs[int(idx)]),])
40    return id
Note: See TracBrowser for help on using the repository browser.