1 | """ |
---|
2 | Utility functions for portal_tab actions modifications. |
---|
3 | """ |
---|
4 | |
---|
5 | from Products.CMFCore.utils import getToolByName |
---|
6 | |
---|
7 | def 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 | |
---|
11 | def 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 | tabs[int(num)].edit(id=id,title=name, action=action, condition=condition) |
---|
16 | return True |
---|
17 | |
---|
18 | def reorderActions(self, idxs): |
---|
19 | """ Reorder portal_tabs actions in given order """ |
---|
20 | idxs = list(map(int,idxs)) |
---|
21 | portal_actions = getToolByName(self, 'portal_actions') |
---|
22 | actions = portal_actions._cloneActions() |
---|
23 | tabs = [[action, actions.index(action)] for action in actions if action.category == 'portal_tabs'] |
---|
24 | for idx in range(len(idxs)): |
---|
25 | actions[tabs[idx][1]] = tabs[idxs[idx]][0] |
---|
26 | portal_actions._actions = tuple(actions) |
---|
27 | return idxs |
---|