Commit 320d9894 authored by Julien Muchembled's avatar Julien Muchembled

Use reference instead of id for new actions.

git-svn-id: https://svn.erp5.org/repos/public/erp5/sandbox/portal_types@29242 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent a1285b84
......@@ -2386,29 +2386,31 @@ class ActionTemplateItem(ObjectTemplateItem):
BaseTemplateItem.build(self, context, **kw)
p = context.getPortalObject()
for id in self._archive.keys():
relative_url, value = id.split(' | ')
obj = p.unrestrictedTraverse(relative_url)
if USE_BASE_TYPE and obj.getParentId() == 'portal_types':
action = obj._exportOldAction(value)
else:
for ai in obj.listActions():
if getattr(ai, 'id') == value:
url, value = id.split(' | ')
url = posixpath.split(url)
obj = p.unrestrictedTraverse(url)
is_new_action = USE_BASE_TYPE and obj.getParentId() == 'portal_types'
id_id = is_new_action and 'reference' or 'id'
for action in obj.listActions():
if getattr(action, id_id) == value:
break
else:
if self.is_bt_for_diff:
continue
raise NotFound('Action %r not found' % id)
action = ai._getCopy(context)
action = self.removeProperties(action)
url = posixpath.split(relative_url)
if is_new_action:
action = obj._exportOldAction(action)
else:
action = action._getCopy(context)
key = posixpath.join(url[-2], url[-1], value)
self._objects[key] = action
self._objects[key] = self.removeProperties(action)
self._objects[key].wl_clearLocks()
def install(self, context, trashbin, **kw):
update_dict = kw.get('object_to_update')
force = kw.get('force')
if context.getTemplateFormatVersion() == 1:
portal_type_dict = {}
p = context.getPortalObject()
for id in self._objects.keys():
if update_dict.has_key(id) or force:
......@@ -2416,20 +2418,22 @@ class ActionTemplateItem(ObjectTemplateItem):
action = update_dict[id]
if action == 'nothing':
continue
path = id.split('/')
container = p.unrestrictedTraverse(path[:-1])
obj = self._objects[id]
path, id = id.rsplit('/', 1)
container = p.unrestrictedTraverse(path)
if USE_BASE_TYPE and container.getParentId() == 'portal_types':
container._importOldAction(self._objects[id])
# XXX future BT should use 'reference' instead of 'id'
reference = getattr(obj, 'reference', None) or obj.id
portal_type_dict.setdefault(path, {})[reference] = obj
continue
obj = container
obj, action = container, obj
action_list = obj.listActions()
for index in range(len(action_list)):
if getattr(action_list[index], 'id') == path[-1]:
if action_list[index].id == id:
# remove previous action
obj.deleteActions(selections=(index,))
action = self._objects[id]
action_text = action.action
if isinstance(action_text, Expression):
action_text = action_text.text
......@@ -2456,6 +2460,13 @@ class ActionTemplateItem(ObjectTemplateItem):
if action.priority > new_priority:
move_down_list.append(str(index))
obj.moveDownActions(selections=tuple(move_down_list))
for path, action_dict in portal_type_dict.iteritems():
container = p.unrestrictedTraverse(path)
for obj in container.objectValues(meta_type='ERP5 Action Information'):
if obj.reference in action_dict:
container._delObject(obj.id)
for obj in action_dict.itervalues():
container._importOldAction(obj)
else:
BaseTemplateItem.install(self, context, trashbin, **kw)
p = context.getPortalObject()
......@@ -4320,7 +4331,7 @@ class MessageTranslationTemplateItem(BaseTemplateItem):
for lang_key in self._archive.keys():
if '|' in lang_key:
lang, catalog = lang_key.split(' | ')
else: # XXX backward compatibilty
else: # XXX backward compatibility
lang = lang_key
catalog = 'erp5_ui'
path = posixpath.join(lang, catalog)
......
......@@ -43,7 +43,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>base_view</string> </value>
<value> <string>view</string> </value>
</item>
<item>
<key> <string>permissions</string> </key>
......
......@@ -43,7 +43,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>base_view</string> </value>
<value> <string>view</string> </value>
</item>
<item>
<key> <string>permissions</string> </key>
......
......@@ -43,7 +43,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>base_view</string> </value>
<value> <string>view</string> </value>
</item>
<item>
<key> <string>permissions</string> </key>
......
......@@ -43,7 +43,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>base_view</string> </value>
<value> <string>view</string> </value>
</item>
<item>
<key> <string>permissions</string> </key>
......
......@@ -43,7 +43,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>base_view</string> </value>
<value> <string>view</string> </value>
</item>
<item>
<key> <string>permissions</string> </key>
......
......@@ -96,7 +96,7 @@
<key> <string>left</string> </key>
<value>
<list>
<string>my_id</string>
<string>my_reference</string>
<string>my_title</string>
<string>my_action_expression</string>
<string>my_description</string>
......
......@@ -19,7 +19,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>my_id</string> </value>
<value> <string>my_reference</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
......@@ -88,7 +88,7 @@
</item>
<item>
<key> <string>title</string> </key>
<value> <string>ID</string> </value>
<value> <string>Reference</string> </value>
</item>
</dictionary>
</value>
......
......@@ -18,6 +18,7 @@
<string>portal_types</string>
<string>search_columns</string>
<string>selection_name</string>
<string>sort</string>
<string>sort_columns</string>
<string>title</string>
</list>
......@@ -115,8 +116,8 @@
<value>
<list>
<tuple>
<string>id</string>
<string>ID</string>
<string>reference</string>
<string>Reference</string>
</tuple>
<tuple>
<string>title</string>
......@@ -177,13 +178,28 @@
<key> <string>selection_name</string> </key>
<value> <string>action_selection</string> </value>
</item>
<item>
<key> <string>sort</string> </key>
<value>
<list>
<tuple>
<string>action_type_title</string>
<string></string>
</tuple>
<tuple>
<string>float_index</string>
<string></string>
</tuple>
</list>
</value>
</item>
<item>
<key> <string>sort_columns</string> </key>
<value>
<list>
<tuple>
<string>id</string>
<string>ID</string>
<string>reference</string>
<string>Reference</string>
</tuple>
<tuple>
<string>title</string>
......
52
\ No newline at end of file
55
\ No newline at end of file
Action Information | base_view
Action Information | view
Base Type | action_view
Base Type | base_view
Base Type | role_view
Base Type | translation_view
Role Information | base_view
Translation Information | base_view
Types Tool | base_view
\ No newline at end of file
Base Type | view
Role Information | view
Translation Information | view
Types Tool | view
\ No newline at end of file
......@@ -643,48 +643,36 @@ class ERP5TypeInformation(XMLObject,
return sorted(self.objectValues(portal_type='Action Information'),
key=lambda x: x.getFloatIndex())
def _normalizeActionId(self, action_id):
try:
self._checkId(action_id)
except BadRequest:
if not self.hasObject(action_id):
return self._normalizeActionId('action__' + action_id)
return action_id
def _importOldAction(self, old_action):
from Products.ERP5Type.Document.ActionInformation import ActionInformation
old_action = old_action.__getstate__()
action_type = old_action.pop('category', None)
action_id = self._normalizeActionId(old_action.pop('id'))
if self.hasObject(action_id):
self._delObject(action_id)
action = ActionInformation(action_id)
action = ActionInformation(self.generateNewId())
for k, v in old_action.iteritems():
if k in ('action', 'condition', 'icon'):
if not v:
continue
v = v.__class__(v.text)
elif k == 'priority':
k = 'float_index'
setattr(action, k, v)
setattr(action, {'id': 'reference',
'priority': 'float_index',
}.get(k, k), v)
action.uid = None
action = self[self._setObject(action.id, action, set_owner=0)]
if action_type:
action._setCategoryMembership('action_type', action_type)
return action
def _exportOldAction(self, action_id):
def _exportOldAction(self, action):
from Products.CMFCore.ActionInformation import ActionInformation
action = self[self._normalizeActionId(action_id)]
old_action = ActionInformation(action_id,
category = action.getActionType(),
old_action = ActionInformation(action.reference,
category=action.getActionType(),
# We don't have the same default values for the following properties:
priority=action.getFloatIndex(),
permissions=tuple(action.getActionPermissionList()))
for k, v in action.__dict__.iteritems():
if k in ('action', 'condition', 'icon'):
v = v.__class__(v.text)
elif k in ('id', 'float_index', 'permissions'):
elif k in ('id', 'float_index', 'permissions', 'reference'):
continue
setattr(old_action, k, v)
return old_action
......
......@@ -34,6 +34,10 @@ class ActionInformation:
"""
_properties = (
{ 'id': 'reference',
'type': 'string',
'mode': 'w',
},
{ 'id': 'condition',
'type': 'object',
'description': 'TALES Expression to define the applicability of the' \
......
......@@ -39,15 +39,14 @@ def CMFCoreUtils_getViewFor(obj, view='view'):
ti = obj.getTypeInfo()
if ti is not None:
view_id = ti._normalizeActionId(view)
context = getActionContext( obj )
test_context = getExprContext(obj, obj) # Patch 1: mimic _listActionInfos in ActionsTool
actions = ti.listActions()
for action in actions:
# portal_types hack
action_type = action.getActionType()
if action.getId() == view_id or action_type.endswith('_%s' % view):
# Patch 2: consider anything ending by _view
reference = getattr(action, 'reference', None) or action.id
if reference == view or action_type.endswith('_%s' % view): # Patch 2: consider anything ending by _view
if _verifyActionPermissions(obj, action):
if action.isVisible() and action.testCondition(test_context): # Patch 3: test actions
target = action.action(context).strip()
......
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