1 | """ |
---|
2 | Utility functions for portal_tab actions modifications. |
---|
3 | """ |
---|
4 | from Products.CMFCore.Expression import Expression |
---|
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 | 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 | |
---|
22 | def 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 | |
---|
33 | def 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 |
---|