Commit b88384e9 authored by Romain Courteaud's avatar Romain Courteaud

Activate CategoryMembershipState.

Make it more generic.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@20950 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent afae7b7c
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
############################################################################## ##############################################################################
from Products.ERP5Type.Constraint.Constraint import Constraint from Products.ERP5Type.Constraint.Constraint import Constraint
from Products.ERP5Type.Utils import convertToUpperCase # from Products.ERP5Type.Utils import convertToUpperCase
class CategoryMembershipState(Constraint): class CategoryMembershipState(Constraint):
""" """
...@@ -44,6 +44,11 @@ class CategoryMembershipState(Constraint): ...@@ -44,6 +44,11 @@ class CategoryMembershipState(Constraint):
'validation_state': ('validated', ), 'validation_state': ('validated', ),
}, },
""" """
_message_id_list = ['message_different_state']
message_different_state = \
"${workflow_variable} for object ${membership_url} is ${current_state}" \
"which is not in ${valid_state_list}"
def checkConsistency(self, obj, fixit=0): def checkConsistency(self, obj, fixit=0):
""" """
...@@ -53,7 +58,9 @@ class CategoryMembershipState(Constraint): ...@@ -53,7 +58,9 @@ class CategoryMembershipState(Constraint):
are defined the minimum and the maximum arity, and the are defined the minimum and the maximum arity, and the
list of objects we wants to check the arity. list of objects we wants to check the arity.
""" """
errors = [] if not self._checkConstraintCondition(obj):
return []
error_list = []
# Retrieve values inside de PropertySheet (_constraints) # Retrieve values inside de PropertySheet (_constraints)
base_category = self.constraint_definition['base_category'] base_category = self.constraint_definition['base_category']
portal_type = self.constraint_definition['portal_type'] portal_type = self.constraint_definition['portal_type']
...@@ -65,14 +72,16 @@ class CategoryMembershipState(Constraint): ...@@ -65,14 +72,16 @@ class CategoryMembershipState(Constraint):
for workflow_variable, valid_state_list in state_var_list.items(): for workflow_variable, valid_state_list in state_var_list.items():
for membership in membership_list: for membership in membership_list:
method = getattr(membership, current_state = membership.getProperty(workflow_variable)
'get%s' % convertToUpperCase(workflow_variable))
current_state = method()
if current_state not in valid_state_list: if current_state not in valid_state_list:
# Generate error message mapping = dict(workflow_variable=workflow_variable,
error_message = "'%s' for object '%s' is '%s' which is not in " \ membership_url=membership.getRelativeUrl(),
"'%s'" % (workflow_variable, membership.getRelativeUrl(), current_state=current_state,
current_state, str(valid_state_list)) valid_state_list=str(valid_state_list),)
message_id = 'message_different_state'
# Add error # Add error
errors.append(self._generateError(obj, error_message)) error_list.append(self._generateError(obj,
return errors self._getMessage(message_id), mapping))
return error_list
...@@ -11,3 +11,4 @@ from CategoryAcquiredMembershipArity import CategoryAcquiredMembershipArity ...@@ -11,3 +11,4 @@ from CategoryAcquiredMembershipArity import CategoryAcquiredMembershipArity
from TALESConstraint import TALESConstraint from TALESConstraint import TALESConstraint
from ContentExistence import ContentExistence from ContentExistence import ContentExistence
from StringAttributeMatch import StringAttributeMatch from StringAttributeMatch import StringAttributeMatch
from CategoryMembershipState import CategoryMembershipState
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