Commit 81ea431c authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

* cache Action Information definitions for a Portal Type.

* add base_type_interaction_workflow that clears the cache above when Action Information documents are modified or deleted.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@29689 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 3bd9084c
<workflow_chain>
<chain>
<type>Action Information</type>
<workflow>base_type_interaction_workflow</workflow>
</chain>
<chain>
<type>Base Category</type>
<workflow>edit_workflow</workflow>
</chain>
<chain>
<type>Base Type</type>
<workflow>base_type_interaction_workflow</workflow>
</chain>
<chain>
<type>Category</type>
<workflow>edit_workflow</workflow>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<global name="InteractionWorkflowDefinition" module="Products.ERP5.InteractionWorkflow"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>groups</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>base_type_interaction_workflow</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<global name="Interaction" module="Products.ERP5.Interaction"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_mapping</string> </key>
<value>
<dictionary/>
</value>
</item>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>interactions</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<global name="InteractionDefinition" module="Products.ERP5.Interaction"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>actbox_category</string> </key>
<value> <string>workflow</string> </value>
</item>
<item>
<key> <string>actbox_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>actbox_url</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>activate_script_name</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>after_script_name</string> </key>
<value>
<list>
<string>ActionInformation_clearCache</string>
</list>
</value>
</item>
<item>
<key> <string>before_commit_script_name</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>guard</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ActionInformation_set</string> </value>
</item>
<item>
<key> <string>method_id</string> </key>
<value>
<list>
<string>_set.*</string>
</list>
</value>
</item>
<item>
<key> <string>once_per_transaction</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>portal_type_filter</string> </key>
<value>
<list>
<string>Action Information</string>
</list>
</value>
</item>
<item>
<key> <string>script_name</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>trigger_type</string> </key>
<value> <int>2</int> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<global name="InteractionDefinition" module="Products.ERP5.Interaction"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>actbox_category</string> </key>
<value> <string>workflow</string> </value>
</item>
<item>
<key> <string>actbox_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>actbox_url</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>activate_script_name</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>after_script_name</string> </key>
<value>
<list>
<string>BaseType_clearCache</string>
</list>
</value>
</item>
<item>
<key> <string>before_commit_script_name</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>guard</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>BaseType_delete</string> </value>
</item>
<item>
<key> <string>method_id</string> </key>
<value>
<list>
<string>_delObject</string>
</list>
</value>
</item>
<item>
<key> <string>once_per_transaction</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>portal_type_filter</string> </key>
<value>
<list>
<string>Base Type</string>
</list>
</value>
</item>
<item>
<key> <string>script_name</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>trigger_type</string> </key>
<value> <int>2</int> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<global name="Scripts" module="Products.DCWorkflow.Scripts"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_mapping</string> </key>
<value>
<dictionary/>
</value>
</item>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>scripts</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </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>base_type = state_change[\'object\'].aq_parent\n
base_type.clearGetRawActionInformationListCache()\n
</string> </value>
</item>
<item>
<key> <string>_code</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>state_change</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>state_change</string>
<string>_getattr_</string>
<string>_getitem_</string>
<string>base_type</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>ActionInformation_clearCache</string> </value>
</item>
<item>
<key> <string>warnings</string> </key>
<value>
<tuple/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </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>base_type = state_change[\'object\']\n
base_type.clearGetRawActionInformationListCache()\n
</string> </value>
</item>
<item>
<key> <string>_code</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>state_change</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>state_change</string>
<string>_getitem_</string>
<string>base_type</string>
<string>_getattr_</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>BaseType_clearCache</string> </value>
</item>
<item>
<key> <string>warnings</string> </key>
<value>
<tuple/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<global name="Variables" module="Products.DCWorkflow.Variables"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_mapping</string> </key>
<value>
<dictionary/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>variables</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<global name="Worklists" module="Products.DCWorkflow.Worklists"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_mapping</string> </key>
<value>
<dictionary/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>worklists</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
1337
\ No newline at end of file
1338
\ No newline at end of file
Action Information | base_type_interaction_workflow
Base Category | edit_workflow
Base Type | base_type_interaction_workflow
Category | edit_workflow
Distributed Ram Cache | distributed_ram_cache_interaction_workflow
Document | edit_workflow
......
base_type_interaction_workflow
distributed_ram_cache_interaction_workflow
edit_workflow
memcached_plugin_interaction_workflow
......
......@@ -174,3 +174,64 @@ class ActionInformation(XMLObject):
# better performance.
categories = getattr(self, 'categories', [])
return len(categories) and categories[0][12:] or None
security.declarePrivate('getRawActionInformation')
def getRawActionInformation(self):
"""Return RawActionInformation instance that is not persistent and
is cacheable."""
return RawActionInformation(
{'id':self.getReference(),
'name':self.getTitle(),
'description':self.getDescription(),
'category':self.getActionType(),
'priority':self.getFloatIndex(),
'icon':self.getIcon(),
'action':self.getAction(),
'condition':self.getCondition(),
'action_permission':self.getActionPermissionList(),
}
)
class RawActionInformation(object):
"""The purpose of this class is to provide a cacheable instance having
an enough information of Action Information document."""
def __init__(self, kw):
self.action = kw.pop('action')
self.icon = kw.pop('icon')
self.condition = kw.pop('condition')
self.action_permission = kw.pop('action_permission')
self.param_dict = kw
def getPriority(self):
return self.param_dict['priority']
def test(self, ec):
"""Test if the action should be displayed or not for the given context"""
permission_list = self.action_permission
if permission_list:
category = self.param_dict['category'] or ''
info = ec.vars
if (info['here'] is not None and
(category[:6] == 'object' or
category[:8] == 'workflow')):
context = info['here']
elif (info['folder'] is not None and
category[:6] == 'folder'):
context = info['folder']
else:
context = info['portal']
has_permission = getSecurityManager().getUser().has_permission
for permission in permission_list:
if not has_permission(permission, context):
return False
condition = self.condition
return condition is None or condition(ec)
def cook(self, ec):
param_dict = self.param_dict.copy()
action = self.action
param_dict['url'] = action is not None and action(ec) or ''
icon = self.icon
param_dict['icon'] = icon is not None and icon(ec) or ''
return param_dict
......@@ -33,6 +33,7 @@ from Products.ERP5Type import interfaces, Constraint, Permissions, PropertySheet
from Products.ERP5Type.UnrestrictedMethod import UnrestrictedMethod
from Products.ERP5Type.Utils import deprecated, createExpressionContext
from Products.ERP5Type.XMLObject import XMLObject
from Products.ERP5Type.Cache import CachingMethod
ERP5TYPE_SECURITY_GROUP_ID_GENERATION_SCRIPT = 'ERP5Type_asSecurityGroupId'
......@@ -521,6 +522,27 @@ class ERP5TypeInformation(XMLObject,
__traceback_info__ = self.getId(), target
return ob.restrictedTraverse(target)
def _getRawActionInformationList(self):
return sorted(
(x.getRawActionInformation() for x in \
self.getActionInformationList() if x.isVisible()),
key=lambda x:x.getPriority())
_getRawActionInformationList = CachingMethod(
_getRawActionInformationList,
id='_getRawActionInformationList',
cache_factory='erp5_content_long')
security.declarePrivate('getRawActionInformationList')
def getRawActionInformationList(self):
"""Return all visible action informations sorted by priority."""
return self._getRawActionInformationList(self, scope=self.id)
security.declareProtected(Permissions.ModifyPortalContent,
'clearGetRawActionInformationListCache')
def clearGetRawActionInformationListCache(self):
"""Clear a cache of _getRawActionInformationList."""
self._getRawActionInformationList.delete(scope=self.id)
security.declarePrivate('getActionListFor')
def getActionListFor(self, ob=None):
"""Return all actions of the object"""
......
......@@ -42,6 +42,15 @@ class TypesTool(BaseTool, CMFCore_TypesTool.TypesTool):
zope.interface.implements(interfaces.IActionProvider)
security.declarePrivate('getRawActionInformationListFor')
def getRawActionInformationListFor(self, ob=None):
"""Return all action informations of the object"""
if ob is not None:
type_info = self.getTypeInfo(ob)
if type_info is not None:
return type_info.getRawActionInformationList()
return ()
security.declarePrivate('getActionListFor')
def getActionListFor(self, ob=None):
"""Return all actions of the object"""
......
......@@ -39,11 +39,10 @@ def listFilteredActionsFor(self, object=None):
elif hasattr(provider, 'getActionListFor'):
from Products.ERP5Type.Utils import createExpressionContext
ec = createExpressionContext(object)
actions += sorted(
(action.getActionInfo(ec)
for action in provider.getActionListFor(object)
if action.test(ec)),
key=lambda x: x['priority'])
actions.extend(
(action.cook(ec)
for action in provider.getRawActionInformationListFor(object)
if action.test(ec)))
else:
# for Action Providers written for CMF versions before 1.5
actions.extend( self._listActionInfos(provider, object) )
......
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