Commit dd2505f5 authored by Arnaud Fontaine's avatar Arnaud Fontaine

WIP: Fix testDynamicClassGeneration failures.

parent cf937f3e
...@@ -31,6 +31,7 @@ from Products.ERP5Type.mixin.component import ComponentMixin ...@@ -31,6 +31,7 @@ from Products.ERP5Type.mixin.component import ComponentMixin
from Products.ERP5Type.mixin.text_content_history import TextContentHistoryMixin from Products.ERP5Type.mixin.text_content_history import TextContentHistoryMixin
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions from Products.ERP5Type import Permissions
from Products.ERP5Type.ConsistencyMessage import ConsistencyMessage
import zope.interface import zope.interface
from Products.ERP5Type.interfaces.component import IComponent from Products.ERP5Type.interfaces.component import IComponent
...@@ -62,3 +63,24 @@ class DocumentComponent(ComponentMixin, TextContentHistoryMixin): ...@@ -62,3 +63,24 @@ class DocumentComponent(ComponentMixin, TextContentHistoryMixin):
@staticmethod @staticmethod
def getIdPrefix(): def getIdPrefix():
return 'document' return 'document'
_message_reference_class_not_defined = "Class ${reference} must be defined"
def checkConsistency(self, *args, **kw):
"""
Per convention, a Document Component must have at least a class whose name
is the same as the Reference so that it can be assigned to Portal Types.
XXX: Very basic check for now.
"""
error_list = super(DocumentComponent, self).checkConsistency(*args ,**kw)
reference = self.getReference()
text_content = self.getTextContent()
if (reference and text_content and # Already checked in the parent class
'class %s(' % reference not in text_content):
error_list.append(ConsistencyMessage(
self,
self.getRelativeUrl(),
message=self._message_reference_class_not_defined,
mapping={'reference': reference}))
return error_list
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
############################################################################## ##############################################################################
from Products.ERP5Type.Core.DocumentComponent import DocumentComponent from Products.ERP5Type.Core.DocumentComponent import DocumentComponent
from Products.ERP5Type.ConsistencyMessage import ConsistencyMessage
class InterfaceComponent(DocumentComponent): class InterfaceComponent(DocumentComponent):
""" """
...@@ -43,3 +44,20 @@ class InterfaceComponent(DocumentComponent): ...@@ -43,3 +44,20 @@ class InterfaceComponent(DocumentComponent):
@staticmethod @staticmethod
def getIdPrefix(): def getIdPrefix():
return 'interface' return 'interface'
_message_reference_wrong_naming = "Interface Reference must start with 'I'"
def checkConsistency(self, *args, **kw):
"""
Per convention, an Interface class must start with 'I'
"""
error_list = super(InterfaceComponent, self).checkConsistency(*args, **kw)
reference = self.getReference()
if (reference and # Already checked in the parent class
not reference.startswith('I')):
error_list.append(ConsistencyMessage(
self,
self.getRelativeUrl(),
message=self._message_reference_wrong_naming,
mapping={}))
return error_list
...@@ -43,3 +43,20 @@ class MixinComponent(DocumentComponent): ...@@ -43,3 +43,20 @@ class MixinComponent(DocumentComponent):
@staticmethod @staticmethod
def getIdPrefix(): def getIdPrefix():
return 'mixin' return 'mixin'
_message_reference_wrong_naming = "Mixin Reference must end with 'Mixin'"
def checkConsistency(self, *args, **kw):
"""
Per convention, a Mixin class must end with 'Mixin'
"""
error_list = super(MixinComponent, self).checkConsistency(*args, **kw)
reference = self.getReference()
if (reference and # Already checked in the parent class
not reference.endswith('Mixin')):
error_list.append(ConsistencyMessage(
self,
self.getRelativeUrl(),
message=self._message_reference_wrong_naming,
mapping={}))
return error_list
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