def _checkConsistency(self, obj, fixit=0):
        """Check the object's consistency.
    Check that each attribute matches the regular expression.
    """
        error_list = PropertyExistenceConstraint._checkConsistency(self,
                                                                   obj,
                                                                   fixit=fixit)
        if not error_list:
            regular_expression = self.getRegularExpression()
            regexp = re.compile(regular_expression)
            for property_id in self.getConstraintPropertyList():
                # If property does not exist, error will be raised by
                # PropertyExistence Constraint.
                current_value = obj.getProperty(property_id)
                if (current_value is not None) and \
                    (regexp.match(current_value) is None):

                    # Generate error
                    error_list.append(
                        self._generateError(
                            obj,
                            self._getMessage("message_attribute_not_match"),
                            mapping=dict(
                                attribute_name=property_id,
                                attribute_value=repr(current_value),
                                regular_expression=repr(regular_expression))))
        return error_list
Esempio n. 2
0
  def _checkConsistency(self, obj, fixit=0):
    """Check the object's consistency.
      We will make sure that each non None constraint_definition is 
      satisfied (unicity)
      This Constraint use portal_catalog
    """
    error_list = PropertyExistenceConstraint._checkConsistency(self, obj, 
                                                           fixit=fixit)
    attribute_name = self.getConstraintProperty()
    expression_criterion_dict = self.getFilterParameter()

    message_id = None
    mapping = dict(attribute_name=attribute_name)
    #Evaluate expression_criterion_dict
    expression = Expression(expression_criterion_dict)
    econtext = createExpressionContext(obj)
    criterion_dict = expression(econtext)
    # Add uid in criterion keys to avoid fetching current object.
    criterion_dict['query'] = NegatedQuery(Query(uid=obj.getUid()))
    portal = obj.getPortalObject()
    result = portal.portal_catalog.countResults(**criterion_dict)[0][0]
    if result >= 1:
      mapping['value'] = criterion_dict.get(attribute_name)
      message_id = 'message_invalid_attribute_unicity'
    # Generate error
    if message_id is not None:
      error_list.append(self._generateError(obj,
                      self._getMessage(message_id), mapping))

    return error_list
    def _preConvertBaseFromFilesystemDefinition(filesystem_definition_dict):
        """
    'message_property_does_not_match' has been renamed to
    'message_property_not_match' to follow ERP5 naming conventions
    """
        filesystem_definition_dict['message_property_not_match'] = \
            filesystem_definition_dict.pop('message_property_does_not_match',
                                           None)

        return PropertyExistenceConstraint._preConvertBaseFromFilesystemDefinition(
            filesystem_definition_dict)
  def _preConvertBaseFromFilesystemDefinition(filesystem_definition_dict):
    """
    'message_property_does_not_match' has been renamed to
    'message_property_not_match' to follow ERP5 naming conventions
    """
    filesystem_definition_dict['message_property_not_match'] = \
        filesystem_definition_dict.pop('message_property_does_not_match',
                                       None)

    return PropertyExistenceConstraint._preConvertBaseFromFilesystemDefinition(
      filesystem_definition_dict)
  def _checkConsistency(self, obj, fixit=0):
    """Check the object's consistency.
      We will make sure that each non None constraint_definition is 
      satisfied
    """
    error_list = PropertyExistenceConstraint._checkConsistency(
                                                   self, obj, fixit=fixit)
    blacklisted_list_expression = self.getBlacklistedList()
    expression_context = createExpressionContext(obj)
    blacklisted_list = evaluateExpressionFromString(expression_context,
                                                    blacklisted_list_expression)
    message_id = 'message_invalid_attribute_blacklisted'
    for property_id in self.getConstraintPropertyList():

      value = obj.getProperty(property_id)
      if value in blacklisted_list:
        mapping = dict(attribute_name=property_id)
        # Generate error
        error_list.append(self._generateError(obj, 
                                              self._getMessage(message_id),
                                              mapping=mapping)
                         )
    return error_list
  def _checkConsistency(self, obj, fixit=0):
    """Check the object's consistency.
      We will make sure that each non None constraint_definition is
      satisfied
    """
    error_list = PropertyExistenceConstraint._checkConsistency(
                                                   self, obj, fixit=fixit)
    blacklisted_list_expression = self.getBlacklistedList()
    expression_context = createExpressionContext(obj)
    blacklisted_list = evaluateExpressionFromString(expression_context,
                                                    blacklisted_list_expression)
    message_id = 'message_invalid_attribute_blacklisted'
    for property_id in self.getConstraintPropertyList():

      value = obj.getProperty(property_id)
      if value in blacklisted_list:
        mapping = dict(attribute_name=property_id)
        # Generate error
        error_list.append(self._generateError(obj,
                                              self._getMessage(message_id),
                                              mapping=mapping)
                         )
    return error_list
 def _checkConsistency(self, obj, fixit=0):
   """Check the object's consistency.
   Check that each attribute matches the regular expression.
   """
   error_list = PropertyExistenceConstraint._checkConsistency(
                                               self, obj, fixit=fixit)
   if not error_list:
     regular_expression = self.getRegularExpression()
     regexp = re.compile(regular_expression)
     for property_id in self.getConstraintPropertyList():
       # If property does not exist, error will be raised by 
       # PropertyExistence Constraint.
       current_value = obj.getProperty(property_id)
       if (current_value is not None) and \
           (regexp.match(current_value) is None):
   
         # Generate error
         error_list.append(self._generateError(
                      obj, 
                      self._getMessage("message_attribute_not_match"),
           mapping=dict(attribute_name=property_id,
                        attribute_value=repr(current_value),
                        regular_expression=repr(regular_expression))))
   return error_list