diff --git a/product/ERP5/Document/BusinessTemplate.py b/product/ERP5/Document/BusinessTemplate.py index b93f29f2caaf6cb057a4c018bca2e9dbb082272f..f8aae9b5a9499648e5349330de86d18afd458499 100644 --- a/product/ERP5/Document/BusinessTemplate.py +++ b/product/ERP5/Document/BusinessTemplate.py @@ -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) + 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: - for ai in obj.listActions(): - if getattr(ai, '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 self.is_bt_for_diff: + continue + raise NotFound('Action %r not found' % id) + 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) diff --git a/product/ERP5/bootstrap/erp5_type/ActionTemplateItem/portal_types/Action%20Information/base_view.xml b/product/ERP5/bootstrap/erp5_type/ActionTemplateItem/portal_types/Action%20Information/view.xml similarity index 97% rename from product/ERP5/bootstrap/erp5_type/ActionTemplateItem/portal_types/Action%20Information/base_view.xml rename to product/ERP5/bootstrap/erp5_type/ActionTemplateItem/portal_types/Action%20Information/view.xml index 38ba8338e2aca06bd1c6a828c16dcc7c0baec968..8e9ff396d0d6c797996419762fbffebe9332b367 100644 --- a/product/ERP5/bootstrap/erp5_type/ActionTemplateItem/portal_types/Action%20Information/base_view.xml +++ b/product/ERP5/bootstrap/erp5_type/ActionTemplateItem/portal_types/Action%20Information/view.xml @@ -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> diff --git a/product/ERP5/bootstrap/erp5_type/ActionTemplateItem/portal_types/Base%20Type/base_view.xml b/product/ERP5/bootstrap/erp5_type/ActionTemplateItem/portal_types/Base%20Type/view.xml similarity index 97% rename from product/ERP5/bootstrap/erp5_type/ActionTemplateItem/portal_types/Base%20Type/base_view.xml rename to product/ERP5/bootstrap/erp5_type/ActionTemplateItem/portal_types/Base%20Type/view.xml index ca393b46ae41f8b3ed24c4bd4de95b749532191f..ef7a2513af916ba7eddfc913cee1ca2bc106e3a3 100644 --- a/product/ERP5/bootstrap/erp5_type/ActionTemplateItem/portal_types/Base%20Type/base_view.xml +++ b/product/ERP5/bootstrap/erp5_type/ActionTemplateItem/portal_types/Base%20Type/view.xml @@ -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> diff --git a/product/ERP5/bootstrap/erp5_type/ActionTemplateItem/portal_types/Role%20Information/base_view.xml b/product/ERP5/bootstrap/erp5_type/ActionTemplateItem/portal_types/Role%20Information/view.xml similarity index 97% rename from product/ERP5/bootstrap/erp5_type/ActionTemplateItem/portal_types/Role%20Information/base_view.xml rename to product/ERP5/bootstrap/erp5_type/ActionTemplateItem/portal_types/Role%20Information/view.xml index f5fb8a72865edf563a935dbd4f8c992037fa807d..47feb878f15db6ede36d07bccbb2c14b48f512f0 100644 --- a/product/ERP5/bootstrap/erp5_type/ActionTemplateItem/portal_types/Role%20Information/base_view.xml +++ b/product/ERP5/bootstrap/erp5_type/ActionTemplateItem/portal_types/Role%20Information/view.xml @@ -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> diff --git a/product/ERP5/bootstrap/erp5_type/ActionTemplateItem/portal_types/Translation%20Information/base_view.xml b/product/ERP5/bootstrap/erp5_type/ActionTemplateItem/portal_types/Translation%20Information/view.xml similarity index 97% rename from product/ERP5/bootstrap/erp5_type/ActionTemplateItem/portal_types/Translation%20Information/base_view.xml rename to product/ERP5/bootstrap/erp5_type/ActionTemplateItem/portal_types/Translation%20Information/view.xml index 226eccea4062b07953182caa0331e586351cf17e..06b656b49240c740cd135d5626d8b9e5c45158a0 100644 --- a/product/ERP5/bootstrap/erp5_type/ActionTemplateItem/portal_types/Translation%20Information/base_view.xml +++ b/product/ERP5/bootstrap/erp5_type/ActionTemplateItem/portal_types/Translation%20Information/view.xml @@ -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> diff --git a/product/ERP5/bootstrap/erp5_type/ActionTemplateItem/portal_types/Types%20Tool/base_view.xml b/product/ERP5/bootstrap/erp5_type/ActionTemplateItem/portal_types/Types%20Tool/view.xml similarity index 97% rename from product/ERP5/bootstrap/erp5_type/ActionTemplateItem/portal_types/Types%20Tool/base_view.xml rename to product/ERP5/bootstrap/erp5_type/ActionTemplateItem/portal_types/Types%20Tool/view.xml index afb8a1c2fb0646171b62ce89c3e994a1d1ae4198..73d2dda2b5cbcc3f6cabc145c66ad85b8eddc14a 100644 --- a/product/ERP5/bootstrap/erp5_type/ActionTemplateItem/portal_types/Types%20Tool/base_view.xml +++ b/product/ERP5/bootstrap/erp5_type/ActionTemplateItem/portal_types/Types%20Tool/view.xml @@ -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> diff --git a/product/ERP5/bootstrap/erp5_type/SkinTemplateItem/portal_skins/erp5_type/ActionInformation_view.xml b/product/ERP5/bootstrap/erp5_type/SkinTemplateItem/portal_skins/erp5_type/ActionInformation_view.xml index cd13545a2beb380dfd035cb1252a073b496c1eed..55af41f5170341d6444c5dcc3e56923f7b69ed88 100644 --- a/product/ERP5/bootstrap/erp5_type/SkinTemplateItem/portal_skins/erp5_type/ActionInformation_view.xml +++ b/product/ERP5/bootstrap/erp5_type/SkinTemplateItem/portal_skins/erp5_type/ActionInformation_view.xml @@ -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> diff --git a/product/ERP5/bootstrap/erp5_type/SkinTemplateItem/portal_skins/erp5_type/ActionInformation_view/my_id.xml b/product/ERP5/bootstrap/erp5_type/SkinTemplateItem/portal_skins/erp5_type/ActionInformation_view/my_reference.xml similarity index 96% rename from product/ERP5/bootstrap/erp5_type/SkinTemplateItem/portal_skins/erp5_type/ActionInformation_view/my_id.xml rename to product/ERP5/bootstrap/erp5_type/SkinTemplateItem/portal_skins/erp5_type/ActionInformation_view/my_reference.xml index 4b233d6a4873438eece16b5680cd7d74390bd354..6c8c8d2d792c2e22a0f931c8ee25de1882585961 100644 --- a/product/ERP5/bootstrap/erp5_type/SkinTemplateItem/portal_skins/erp5_type/ActionInformation_view/my_id.xml +++ b/product/ERP5/bootstrap/erp5_type/SkinTemplateItem/portal_skins/erp5_type/ActionInformation_view/my_reference.xml @@ -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> diff --git a/product/ERP5/bootstrap/erp5_type/SkinTemplateItem/portal_skins/erp5_type/BaseType_viewAction/listbox.xml b/product/ERP5/bootstrap/erp5_type/SkinTemplateItem/portal_skins/erp5_type/BaseType_viewAction/listbox.xml index 1e73f4f3e4028d8acb3bb13e5b54a9034b84834f..b38f65a0085e117a4f5a29a4009f7753eb6fd943 100644 --- a/product/ERP5/bootstrap/erp5_type/SkinTemplateItem/portal_skins/erp5_type/BaseType_viewAction/listbox.xml +++ b/product/ERP5/bootstrap/erp5_type/SkinTemplateItem/portal_skins/erp5_type/BaseType_viewAction/listbox.xml @@ -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> diff --git a/product/ERP5/bootstrap/erp5_type/bt/revision b/product/ERP5/bootstrap/erp5_type/bt/revision index 613955421088a491231b1c6c7766f0f95a5c5824..7c6ba0fe181de786f8f09b1b8cc1ad6bbc1dd5a4 100644 --- a/product/ERP5/bootstrap/erp5_type/bt/revision +++ b/product/ERP5/bootstrap/erp5_type/bt/revision @@ -1 +1 @@ -52 \ No newline at end of file +55 \ No newline at end of file diff --git a/product/ERP5/bootstrap/erp5_type/bt/template_action_path_list b/product/ERP5/bootstrap/erp5_type/bt/template_action_path_list index f4b40301863f3121400dba36811810cdbf420e1c..32ac592d565063eb63e0389cf840b8279721cbe9 100644 --- a/product/ERP5/bootstrap/erp5_type/bt/template_action_path_list +++ b/product/ERP5/bootstrap/erp5_type/bt/template_action_path_list @@ -1,8 +1,8 @@ -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 diff --git a/product/ERP5Type/ERP5Type.py b/product/ERP5Type/ERP5Type.py index c179b23dee3533c1880383b5d8de05fc9e4e2580..226fbfbe3ca6a4bfa8e4ce61839088e7fae28f78 100644 --- a/product/ERP5Type/ERP5Type.py +++ b/product/ERP5Type/ERP5Type.py @@ -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 diff --git a/product/ERP5Type/PropertySheet/ActionInformation.py b/product/ERP5Type/PropertySheet/ActionInformation.py index 81e7eb39cd6aa9bf69bbf1529c2ddf47f0b9b739..e137d0fe439358f4c312a46d7ab6bb5206c7b845 100644 --- a/product/ERP5Type/PropertySheet/ActionInformation.py +++ b/product/ERP5Type/PropertySheet/ActionInformation.py @@ -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' \ diff --git a/product/ERP5Type/patches/CMFCoreUtils.py b/product/ERP5Type/patches/CMFCoreUtils.py index 0e7607d86c8c79acfb200af4c54f58c8bfcd1135..ffc9ffc0294a643bf805c40a093475e271d3e01b 100644 --- a/product/ERP5Type/patches/CMFCoreUtils.py +++ b/product/ERP5Type/patches/CMFCoreUtils.py @@ -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()