Commit 4f9c060a authored by Julien Muchembled's avatar Julien Muchembled

Implement TypesTool.manage_addTypeInformation for compatibility

git-svn-id: https://svn.erp5.org/repos/public/erp5/sandbox/portal_types@29267 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent a3ecc091
...@@ -408,19 +408,12 @@ class ManageModule: ...@@ -408,19 +408,12 @@ class ManageModule:
# set alowed content type # set alowed content type
module_portal_type_value.allowed_content_types = (object_portal_type_id,) module_portal_type_value.allowed_content_types = (object_portal_type_id,)
module_portal_type_value.filter_content_types = 1 module_portal_type_value.filter_content_types = 1
# making a list of all the portal_type actions to be able to delete them
action_list = module_portal_type_value.listActions()
# cleaning all portal_types actions
module_portal_type_value.deleteActions(
selections = range(0, len(action_list)))
# adding usefull actions (in our case the view action) # adding usefull actions (in our case the view action)
module_portal_type_value.addAction( "view" module_portal_type_value.newContent(portal_type='Action Information',
, "View" reference="view",
, "string:${object_url}/%s"%object_names['view_list'] title="View",
, "" action="string:${object_url}/%s" % object_names['view_list'],
, "View" action_type="object_view")
, "object_view"
)
...@@ -443,26 +436,18 @@ class ManageModule: ...@@ -443,26 +436,18 @@ class ManageModule:
id = object_portal_type_id) id = object_portal_type_id)
object_portal_type_value = portal_types[object_portal_type_id] object_portal_type_value = portal_types[object_portal_type_id]
# cleaning all default actions
action_list = object_portal_type_value.listActions()
object_portal_type_value.deleteActions(
selections = range(0, len(action_list)))
# adding usefull actions (in our case the view action) # adding usefull actions (in our case the view action)
object_portal_type_value.addAction( "view", object_portal_type_value.newContent(portal_type='Action Information',
"View", reference="view",
"string:${object_url}/%s" % object_names['view_id'], title="View",
"", action="string:${object_url}/%s" % object_names['view_id'],
"View", action_type="object_view")
"object_view" object_portal_type_value.newContent(portal_type='Action Information',
) reference="print",
object_portal_type_value.addAction( "print" title="Print",
, "Print" action="string:${object_url}/%s" % object_names['view_pdf'],
, "string:${object_url}/%s" % object_names['view_pdf'] action_type="object_print",
, "" float_index=2.0)
, "View"
, "object_print"
, priority=2.0
)
security.declarePublic('registerModule') security.declarePublic('registerModule')
......
...@@ -521,7 +521,7 @@ class ERP5TypeInformation(XMLObject, ...@@ -521,7 +521,7 @@ class ERP5TypeInformation(XMLObject,
# Compatibitility code for actions # Compatibitility code for actions
security.declareProtected(Permissions.ModifyPortalContent, 'addAction') security.declareProtected(Permissions.AddPortalContent, 'addAction')
@deprecated @deprecated
def addAction(self, id, name, action, condition, permission, category, def addAction(self, id, name, action, condition, permission, category,
icon=None, visible=1, priority=1.0, REQUEST=None, icon=None, visible=1, priority=1.0, REQUEST=None,
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
# #
############################################################################## ##############################################################################
import imp, sys import imp, sys, warnings
import zope.interface import zope.interface
from Acquisition import aq_base from Acquisition import aq_base
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
...@@ -74,6 +74,51 @@ class TypesTool(BaseTool, CMFCore_TypesTool.TypesTool): ...@@ -74,6 +74,51 @@ class TypesTool(BaseTool, CMFCore_TypesTool.TypesTool):
else: else:
return None return None
security.declareProtected(Permissions.AddPortalContent,
'manage_addTypeInformation')
def manage_addTypeInformation(self, add_meta_type, id=None,
typeinfo_name=None, RESPONSE=None):
"""
Create a TypeInformation in self.
"""
if add_meta_type != 'ERP5 Type Information' or RESPONSE is not None:
raise ValueError
fti = None
if typeinfo_name:
info = self.listDefaultTypeInformation()
# Nasty workaround to stay backwards-compatible
# This workaround will disappear in CMF 1.7
if typeinfo_name.endswith(')'):
# This is a new-style name. Proceed normally.
for name, ft in info:
if name == typeinfo_name:
fti = ft
break
else:
# Attempt to work around the old way
# This attempt harbors the problem that the first match on
# meta_type will be used. There could potentially be more
# than one TypeInformation sharing the same meta_type.
warnings.warn('Please switch to the new format for typeinfo names '
'\"product_id: type_id (meta_type)\", the old '
'spelling will disappear in CMF 1.7', DeprecationWarning)
ti_prod, ti_mt = [x.strip() for x in typeinfo_name.split(':')]
for name, ft in info:
if name.startswith(ti_prod) and name.endswith('(%s)' % ti_mt):
fti = ft
break
if fti is None:
raise ValueError('%s not found.' % typeinfo_name)
if not id:
id = fti.get('id')
if not id:
raise ValueError('An id is required.')
type_info = self.newContent(id, 'Base Type')
if fti:
type_info.__dict__.update(**fti)
# Compatibility code to access old "ERP5 Role Information" objects. # Compatibility code to access old "ERP5 Role Information" objects.
OldRoleInformation = imp.new_module('Products.ERP5Type.RoleInformation') OldRoleInformation = imp.new_module('Products.ERP5Type.RoleInformation')
sys.modules[OldRoleInformation.__name__] = OldRoleInformation sys.modules[OldRoleInformation.__name__] = OldRoleInformation
......
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