Commit 6c67fada authored by Arnaud Fontaine's avatar Arnaud Fontaine

Cosmetic: move checkConsistency error messages to class attributes.

parent 2388b36a
...@@ -143,6 +143,17 @@ class ComponentMixin(PropertyRecordableMixin, Base): ...@@ -143,6 +143,17 @@ class ComponentMixin(PropertyRecordableMixin, Base):
'Reference', 'Reference',
'TextDocument') 'TextDocument')
_message_reference_not_set = "Reference must be set"
_message_invalid_reference = "Reference cannot end with '_version' or "\
"start with '_' or be equal to find_module or load_module"
_message_version_not_set = "Version must be set"
_message_invalid_version = "Version cannot start with '_'"
_message_text_content_not_set = "No source code"
_message_invalid_text_content = "Source code: ${error_message}"
_message_text_content_syntax_error = "Syntax error in source code: "\
"${error_message} (line: ${line_number}, column: ${column_number})"
security.declareProtected(Permissions.ModifyPortalContent, 'checkConsistency') security.declareProtected(Permissions.ModifyPortalContent, 'checkConsistency')
def checkConsistency(self, *args, **kw): def checkConsistency(self, *args, **kw):
""" """
...@@ -156,7 +167,7 @@ class ComponentMixin(PropertyRecordableMixin, Base): ...@@ -156,7 +167,7 @@ class ComponentMixin(PropertyRecordableMixin, Base):
error_list.append( error_list.append(
ConsistencyMessage(self, ConsistencyMessage(self,
object_relative_url, object_relative_url,
message="Reference must be set", message=self._message_reference_not_set,
mapping={})) mapping={}))
elif (reference.endswith('_version') or elif (reference.endswith('_version') or
...@@ -165,21 +176,19 @@ class ComponentMixin(PropertyRecordableMixin, Base): ...@@ -165,21 +176,19 @@ class ComponentMixin(PropertyRecordableMixin, Base):
error_list.append( error_list.append(
ConsistencyMessage(self, ConsistencyMessage(self,
object_relative_url, object_relative_url,
message="Reference cannot end with '_version' or "\ message=self._message_invalid_reference,
"start with '_' or be equal to find_module or "\
"load_module",
mapping={})) mapping={}))
version = self.getVersion() version = self.getVersion()
if not version: if not version:
error_list.append(ConsistencyMessage(self, error_list.append(ConsistencyMessage(self,
object_relative_url, object_relative_url,
message="Version must be set", message=self._message_version_not_set,
mapping={})) mapping={}))
elif version[0] == '_': elif version[0] == '_':
error_list.append(ConsistencyMessage(self, error_list.append(ConsistencyMessage(self,
object_relative_url, object_relative_url,
message="Version cannot start with '_'", message=self._message_invalid_version,
mapping={})) mapping={}))
text_content = self.getTextContent() text_content = self.getTextContent()
...@@ -187,7 +196,7 @@ class ComponentMixin(PropertyRecordableMixin, Base): ...@@ -187,7 +196,7 @@ class ComponentMixin(PropertyRecordableMixin, Base):
error_list.append( error_list.append(
ConsistencyMessage(self, ConsistencyMessage(self,
object_relative_url=object_relative_url, object_relative_url=object_relative_url,
message="No source code", message=self._message_text_content_not_set,
mapping={})) mapping={}))
else: else:
message = None message = None
...@@ -198,12 +207,11 @@ class ComponentMixin(PropertyRecordableMixin, Base): ...@@ -198,12 +207,11 @@ class ComponentMixin(PropertyRecordableMixin, Base):
line_number=e.lineno, line_number=e.lineno,
column_number=e.offset) column_number=e.offset)
message = "Syntax error in source code: ${error_message} " \ message = self._message_text_content_syntax_error
"(line: ${line_number}, column: ${column_number})"
except Exception, e: except Exception, e:
mapping = dict(error_message=str(e)) mapping = dict(error_message=str(e))
message = "Source code: ${error_message}" message = self._message_invalid_text_content
if message: if message:
error_list.append( error_list.append(
...@@ -240,7 +248,7 @@ class ComponentMixin(PropertyRecordableMixin, Base): ...@@ -240,7 +248,7 @@ class ComponentMixin(PropertyRecordableMixin, Base):
""" """
current_workflow = self.workflow_history['component_validation_workflow'][-1] current_workflow = self.workflow_history['component_validation_workflow'][-1]
return [str(error.getTranslatedMessage()) return [str(error.getTranslatedMessage())
for error in current_workflow['error_list']] for error in current_workflow.get('error_list', [])]
security.declareProtected(Permissions.ModifyPortalContent, 'load') security.declareProtected(Permissions.ModifyPortalContent, 'load')
def load(self, namespace_dict={}, validated_only=False, text_content=None): def load(self, namespace_dict={}, validated_only=False, text_content=None):
......
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