def _createConsistencyMessage(self, object_relative_url, message, mapping): # XXX If I put in the right place I have TypeError: 'NoneType' object is not callable from Products.ERP5Type.ConsistencyMessage import ConsistencyMessage return ConsistencyMessage(self, object_relative_url=object_relative_url, message=message, mapping=mapping)
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() # Already checked in the parent class if reference and text_content: class_definition_str = 'class %s' % reference try: sep = text_content[text_content.index(class_definition_str) + len(class_definition_str)] except (ValueError, IndexError): pass else: if (sep == ':' or # old-style class sep == '('): # new-style class return error_list error_list.append(ConsistencyMessage( self, self.getRelativeUrl(), message=self._message_reference_class_not_defined, mapping={'reference': reference})) return error_list
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() # XXX Handle a few exceptions, following the same rules as in # ERP5Site_checkNamingConventions expected_meta_type = expected_meta_type\ .replace(' S M S ', ' SMS ')\ .replace(' O Auth ', ' OAuth ') 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 _generateError(self, obj, error_message, mapping={}): """Generic method used to generate error in checkConsistency. """ if error_message is not None: msg = ConsistencyMessage(self, object_relative_url=obj.getRelativeUrl(), message=error_message, mapping=mapping) return msg
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
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 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 re.search('[^\s]*class\s+%s\s*[(:]' % reference, text_content) is None): error_list.append( ConsistencyMessage( self, self.getRelativeUrl(), message=self._message_reference_class_not_defined, mapping={'reference': reference})) return error_list
def _createConstraintMessage(self, message): return ConsistencyMessage(self, object_relative_url=self.getRelativeUrl(), message=message)
def checkConsistency(self, *args, **kw): """ Check the consistency of the Component upon validate or when being modified after being validated. Some keywords are forbidden for reference and version. As Version package always ends with '_version', reference is checked more carefully to avoid clashing with existing method names (such as the ones required for PEP 302). XXX-arnau: separate Constraint class? """ error_list = super(ComponentMixin, self).checkConsistency(*args, **kw) object_relative_url = self.getRelativeUrl() reference = self.getReference() reference_has_error = False if not reference: reference_has_error = True error_list.append( ConsistencyMessage(self, object_relative_url, message=self._message_reference_not_set, mapping={})) elif (reference.endswith('_version') or reference[0] == '_' or reference in ('find_module', 'load_module', 'reset')): reference_has_error = True error_list.append( ConsistencyMessage(self, object_relative_url, message=self._message_invalid_reference, mapping={})) version = self.getVersion() if not version: error_list.append(ConsistencyMessage(self, object_relative_url, message=self._message_version_not_set, mapping={})) elif version[0] == '_': error_list.append(ConsistencyMessage(self, object_relative_url, message=self._message_invalid_version, mapping={})) else: package = __import__(self._getDynamicModuleNamespace(), globals(), fromlist=[self._getDynamicModuleNamespace()], level=0) component_id = None component_uid = None from Products.ERP5Type.dynamic import aq_method_lock with aq_method_lock: component_id_uid_tuple = package._registry_dict.get( self.getReference(), {}).get(self.getVersion(), None) if component_id_uid_tuple: component_id, component_uid = component_id_uid_tuple if (component_id is not None and component_uid is not None and not reference_has_error and component_uid != self._p_oid and component_id != self.getId()): error_list.append( ConsistencyMessage(self, object_relative_url, message=self._message_duplicated_version_reference, mapping=dict(id=component_id))) text_content = self.getTextContent() if not text_content: error_list.append( ConsistencyMessage(self, object_relative_url=object_relative_url, message=self._message_text_content_not_set, mapping={})) else: for error_message in self.getTextContentErrorMessageList(): error_list.append(ConsistencyMessage(self, object_relative_url=object_relative_url, message=self._message_text_content_error, mapping=dict(error_message=error_message))) return error_list
def checkConsistency(self, *args, **kw): """ Check the consistency of the Component upon validate or when being modified after being validated. Some keywords are forbidden for reference and version. As Version package always ends with '_version', reference is checked more carefully to avoid clashing with existing method names (such as the ones required for PEP 302). XXX-arnau: separate Constraint class? """ error_list = super(ComponentMixin, self).checkConsistency(*args, **kw) object_relative_url = self.getRelativeUrl() is_id_invalid = False try: prefix, version, reference = self.getId().split('.') except ValueError: is_id_invalid = True else: if (prefix != self.getIdPrefix() or version != self.getVersion() or reference != self.getReference()): is_id_invalid = True if is_id_invalid: error_list.append( ConsistencyMessage(self, object_relative_url, message=self._message_invalid_id, mapping={'id_prefix': self.getIdPrefix()})) reference = self.getReference() if not reference: error_list.append( ConsistencyMessage(self, object_relative_url, message=self._message_reference_not_set, mapping={})) elif (reference.endswith('_version') or reference[0] == '_' or reference in ('find_module', 'load_module', 'reset')): error_list.append( ConsistencyMessage(self, object_relative_url, message=self._message_invalid_reference, mapping={})) version = self.getVersion() if not version: error_list.append( ConsistencyMessage(self, object_relative_url, message=self._message_version_not_set, mapping={})) elif version[0] == '_': error_list.append( ConsistencyMessage(self, object_relative_url, message=self._message_invalid_version, mapping={})) text_content = self.getTextContent() if not text_content: error_list.append( ConsistencyMessage(self, object_relative_url=object_relative_url, message=self._message_text_content_not_set, mapping={})) else: for error_message in self.getTextContentErrorMessageList(): error_list.append( ConsistencyMessage( self, object_relative_url=object_relative_url, message=self._message_text_content_error, mapping=dict(error_message=error_message))) return error_list