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