Commit ea30cba0 authored by Arnaud Fontaine's avatar Arnaud Fontaine

ZODB Components: Tool Component: Check that 'meta_type' is set and valid.

So that it can be registered properly on load and later added through the ZMI.
parent c906bd1a
...@@ -33,6 +33,8 @@ from AccessControl import ClassSecurityInfo ...@@ -33,6 +33,8 @@ from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions from Products.ERP5Type import Permissions
import zope.interface import zope.interface
import re
from Products.ERP5Type.ConsistencyMessage import ConsistencyMessage
from Products.ERP5Type.interfaces.component import IComponent from Products.ERP5Type.interfaces.component import IComponent
from Products.CMFCore import utils from Products.CMFCore import utils
...@@ -49,6 +51,24 @@ class ToolComponent(DocumentComponent): ...@@ -49,6 +51,24 @@ class ToolComponent(DocumentComponent):
security = ClassSecurityInfo() security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation) security.declareObjectProtected(Permissions.AccessContentsInformation)
_message_meta_type_invalid = "'meta_type' class property must be '${meta_type}'"
def checkConsistency(self, *args, **kw):
"""
"""
error_list = super(ToolComponent, self).checkConsistency(*args ,**kw)
if not error_list:
expected_meta_type = 'ERP5 ' + ''.join([(c if c.islower() else ' ' + c)
for c in self.getReference()]).strip()
if re.search(r'^\s*meta_type\s*=\s*[\'"]%s[\'"]\s*$' % expected_meta_type,
self.getTextContent(), re.MULTILINE) is None:
error_list.append(ConsistencyMessage(
self,
self.getRelativeUrl(),
message=self._message_meta_type_invalid,
mapping={'meta_type': expected_meta_type}))
return error_list
def _hookAfterLoad(self, module_obj): def _hookAfterLoad(self, module_obj):
""" """
Register Tool so that it can be added in ZMI through manage_addToolForm. Register Tool so that it can be added in ZMI through manage_addToolForm.
......
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