Commit b3afd86e authored by Jérome Perrin's avatar Jérome Perrin

Filter duplicate actions defined on a document.

Duplicate actions are actions from the same category with the same ID. In the case of duplicate actions, only the first action is shown.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@15737 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent a10f8a94
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<tuple>
<string>Products.PythonScripts.PythonScript</string>
<string>PythonScript</string>
</tuple>
<none/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Python_magic</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>__ac_local_roles__</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>"""This script filters duplicate actions for a document.\n
Duplicate actions are actions with the same ID in the same action category.\n
In case of duplicate, only the first action will be kept.\n
\n
`actions` is the mapping returned by ActionsTool.listFilteredActionsFor\n
The script must be called on the context of the document.\n
"""\n
\n
def filterDuplicateActions(actions):\n
new_actions = dict()\n
\n
for action_category, action_list in actions.items():\n
existing_actions = dict()\n
new_actions[action_category] = []\n
keep_action = new_actions[action_category].append\n
\n
for action in action_list:\n
if action[\'id\'] not in existing_actions:\n
existing_actions[action[\'id\']] = 1\n
keep_action(action)\n
return new_actions\n
\n
\n
def hasDuplicateActions(portal_type, user_name):\n
len_actions = 0\n
len_filtered_actions = 0\n
for cat in actions.values():\n
len_actions += len(cat)\n
filtered_actions = filterDuplicateActions(actions)\n
for cat in filtered_actions.values():\n
len_filtered_actions += len(cat)\n
return len_actions != len_filtered_actions\n
\n
\n
from Products.ERP5Type.Cache import CachingMethod\n
hasDuplicateActions = CachingMethod(\n
hasDuplicateActions,\n
id=\'Base_filterDuplicateActions.hasDuplicateActions\',\n
cache_factory=\'erp5_ui_long\')\n
\n
user_name = str(container.REQUEST.AUTHENTICATED_USER)\n
if hasDuplicateActions(context.getPortalType(), user_name):\n
return filterDuplicateActions(actions)\n
return actions\n
</string> </value>
</item>
<item>
<key> <string>_code</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_filepath</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_owner</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>actions</string> </value>
</item>
<item>
<key> <string>errors</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>func_code</string> </key>
<value>
<object>
<klass>
<global name="FuncCode" module="Shared.DC.Scripts.Signature"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>co_argcount</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>co_varnames</string> </key>
<value>
<tuple>
<string>actions</string>
<string>filterDuplicateActions</string>
<string>hasDuplicateActions</string>
<string>Products.ERP5Type.Cache</string>
<string>CachingMethod</string>
<string>str</string>
<string>_getattr_</string>
<string>container</string>
<string>user_name</string>
<string>context</string>
</tuple>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>func_defaults</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_filterDuplicateActions</string> </value>
</item>
<item>
<key> <string>warnings</string> </key>
<value>
<tuple/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -60,7 +60,7 @@
global portal_path portal/portal_url/getPortalPath;\n
local_parameter_list local_parameter_list | python: {};\n
\n
global actions python: portal.portal_actions.listFilteredActionsFor(here);\n
global actions python: here.Base_filterDuplicateActions(portal.portal_actions.listFilteredActionsFor(here));\n
global url here/absolute_url;\n
global current_form_id python: local_parameter_list.get(\'dialog_id\', local_parameter_list.get(\'form_id\', \'view\'));\n
dummy python: request.set(\'current_form_id\', current_form_id);\n
......
412
\ No newline at end of file
413
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment