Esempio n. 1
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
   """
   errors = PropertyExistence._checkConsistency(self, obj, fixit=fixit)
   for attribute_name, expression_criterion_dict in self.constraint_definition.items():
     message_id = None
     mapping = dict(attribute_name=attribute_name)
     #Evaluate expression_criterion_dict
     expression = Expression(expression_criterion_dict)
     from Products.ERP5Type.Utils import createExpressionContext
     econtext = createExpressionContext(obj)
     criterion_dict = expression(econtext)
     from Products.ZSQLCatalog.SQLCatalog import Query, NegatedQuery
     # 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:
       errors.append(self._generateError(obj,
                       self._getMessage(message_id), mapping))
   return errors
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 (equality)
 """
     errors = PropertyExistence._checkConsistency(self, obj, fixit=fixit)
     for attribute_name, expected_value in self.constraint_definition.items(
     ):
         message_id = None
         mapping = dict()
         # If property does not exist, error will be raised by
         # PropertyExistence Constraint.
         if obj.hasProperty(attribute_name):
             identical = 1
             if isinstance(expected_value, (list, tuple)):
                 # List type
                 if len(obj.getProperty(attribute_name)) != len(
                         expected_value):
                     identical = 0
                 else:
                     for item in obj.getProperty(attribute_name):
                         if item not in expected_value:
                             identical = 0
                             break
             else:
                 # Other type
                 identical = (
                     expected_value == obj.getProperty(attribute_name))
             if not identical:
                 message_id = 'message_invalid_attribute_value'
                 mapping(attribute_name=attribute_name,
                         attribute_value=obj.getProperty(attribute_name),
                         expected_value=expected_value)
         # Generate error
         if message_id is not None:
             if fixit:
                 obj._setProperty(attribute_name, expected_value)
                 message_id = 'message_invalid_attribute_value_fixed'
             errors.append(
                 self._generateError(obj, self._getMessage(message_id),
                                     mapping))
     return errors
Esempio n. 3
0
 def _checkConsistency(self, obj, fixit=0):
     """Check the object's consistency.
   We will make sure that each non None constraint_definition is
   satisfied (equality)
 """
     errors = PropertyExistence._checkConsistency(self, obj, fixit=fixit)
     for attribute_name, expected_value in self.constraint_definition.items():
         message_id = None
         mapping = {}
         # If property does not exist, error will be raised by
         # PropertyExistence Constraint.
         if obj.hasProperty(attribute_name):
             identical = 1
             if isinstance(expected_value, (list, tuple)):
                 # List type
                 if len(obj.getProperty(attribute_name)) != len(expected_value):
                     identical = 0
                 else:
                     for item in obj.getProperty(attribute_name):
                         if item not in expected_value:
                             identical = 0
                             break
             else:
                 # Other type
                 identical = expected_value == obj.getProperty(attribute_name)
             if not identical:
                 message_id = "message_invalid_attribute_value"
                 mapping(
                     attribute_name=attribute_name,
                     attribute_value=obj.getProperty(attribute_name),
                     expected_value=expected_value,
                 )
         # Generate error
         if message_id is not None:
             if fixit:
                 obj._setProperty(attribute_name, expected_value)
                 message_id = "message_invalid_attribute_value_fixed"
             errors.append(self._generateError(obj, self._getMessage(message_id), mapping))
     return errors
Esempio n. 4
0
    def _checkConsistency(self, obj, fixit=0):
        """Check the object's consistency.
      We will make sure that each non None constraint_definition is
      satisfied
    """
        errors = PropertyExistence._checkConsistency(self, obj, fixit=fixit)
        for attribute_name, expression_blacklisted_list in self.constraint_definition.items():
            message_id = None
            mapping = dict(attribute_name=attribute_name)
            # Evaluate expression_criterion_dict
            expression = Expression(expression_blacklisted_list)
            from Products.ERP5Type.Utils import createExpressionContext

            econtext = createExpressionContext(obj)
            blacklisted_list = expression(econtext)
            value = obj.getProperty(attribute_name)
            if value in blacklisted_list:
                message_id = "message_invalid_attribute_blacklisted"
            # Generate error
            if message_id is not None:
                errors.append(self._generateError(obj, self._getMessage(message_id), mapping))
        return errors
Esempio n. 5
0
 def _checkConsistency(self, obj, fixit=0):
     """Check the object's consistency.
   We will make sure that each non None constraint_definition is
   satisfied
 """
     errors = PropertyExistence._checkConsistency(self, obj, fixit=fixit)
     for attribute_name, expression_blacklisted_list in self.constraint_definition.items(
     ):
         message_id = None
         mapping = dict(attribute_name=attribute_name)
         #Evaluate expression_criterion_dict
         expression = Expression(expression_blacklisted_list)
         from Products.ERP5Type.Utils import createExpressionContext
         econtext = createExpressionContext(obj)
         blacklisted_list = expression(econtext)
         value = obj.getProperty(attribute_name)
         if value in blacklisted_list:
             message_id = 'message_invalid_attribute_blacklisted'
         # Generate error
         if message_id is not None:
             errors.append(
                 self._generateError(obj, self._getMessage(message_id),
                                     mapping))
     return errors