[Erp5-report] r40753 arnaud.fontaine - in /erp5/trunk/products/ERP5Type: Core/ PropertyShee...
nobody at svn.erp5.org
nobody at svn.erp5.org
Fri Nov 26 08:09:09 CET 2010
Author: arnaud.fontaine
Date: Fri Nov 26 08:09:08 2010
New Revision: 40753
URL: http://svn.erp5.org?rev=40753&view=rev
Log:
Clean up the code of ZODB Property Sheets Documents by setting default
values in their Property Sheets
Modified:
erp5/trunk/products/ERP5Type/Core/AttributeEqualityConstraint.py
erp5/trunk/products/ERP5Type/Core/CategoryExistenceConstraint.py
erp5/trunk/products/ERP5Type/Core/ContentExistenceConstraint.py
erp5/trunk/products/ERP5Type/Core/PropertyExistenceConstraint.py
erp5/trunk/products/ERP5Type/PropertySheet/AttributeEqualityConstraint.py
erp5/trunk/products/ERP5Type/PropertySheet/CategoryExistenceConstraint.py
erp5/trunk/products/ERP5Type/PropertySheet/ContentExistenceConstraint.py
erp5/trunk/products/ERP5Type/PropertySheet/PropertyExistenceConstraint.py
erp5/trunk/products/ERP5Type/mixin/constraint.py
Modified: erp5/trunk/products/ERP5Type/Core/AttributeEqualityConstraint.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Core/AttributeEqualityConstraint.py?rev=40753&r1=40752&r2=40753&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Core/AttributeEqualityConstraint.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/Core/AttributeEqualityConstraint.py [utf8] Fri Nov 26 08:09:08 2010
@@ -32,8 +32,6 @@
from Products.ERP5Type.mixin.constraint import ConstraintMixin
from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet
-from Products.CMFCore.Expression import Expression
-from Products.ERP5Type.Utils import createExpressionContext
class AttributeEqualityConstraint(ConstraintMixin):
"""
@@ -66,14 +64,6 @@ class AttributeEqualityConstraint(Constr
PropertySheet.Reference,
PropertySheet.AttributeEqualityConstraint)
- # Define by default error messages
- _message_id_list = ['message_invalid_attribute_value',
- 'message_invalid_attribute_value_fixed']
- message_invalid_attribute_value = "Attribute ${attribute_name} "\
- "value is ${current_value} but should be ${expected_value}"
- message_invalid_attribute_value_fixed = "Attribute ${attribute_name} "\
- "value is ${current_value} but should be ${expected_value} (Fixed)"
-
security.declareProtected(Permissions.AccessContentsInformation,
'checkConsistency')
def checkConsistency(self, obj, fixit=False):
@@ -93,11 +83,8 @@ class AttributeEqualityConstraint(Constr
identical = True
# The expected value of the attribute is a TALES Expression
- attribute_expected_value_expression = Expression(
- self.getConstraintAttributeValue())
-
- attribute_expected_value = attribute_expected_value_expression(
- createExpressionContext(obj))
+ attribute_expected_value = self._getExpressionValue(
+ obj, self.getConstraintAttributeValue())
attribute_value = obj.getProperty(attribute_name)
Modified: erp5/trunk/products/ERP5Type/Core/CategoryExistenceConstraint.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Core/CategoryExistenceConstraint.py?rev=40753&r1=40752&r2=40753&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Core/CategoryExistenceConstraint.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/Core/CategoryExistenceConstraint.py [utf8] Fri Nov 26 08:09:08 2010
@@ -53,17 +53,9 @@ class CategoryExistenceConstraint(Constr
PropertySheet.Reference,
PropertySheet.CategoryExistenceConstraint)
- _message_id_list = [ 'message_category_not_set',
- 'message_category_not_associated_with_portal_type' ]
- message_category_not_set = "Category existence error for base"\
- " category ${base_category}, this category is not defined"
- message_category_not_associated_with_portal_type = "Category existence"\
- " error for base category ${base_category}, this"\
- " document has no such category"
-
- def _calculateArity(self, obj, base_category, portal_type):
+ def _calculateArity(self, obj, base_category, portal_type_list):
return len(obj.getCategoryMembershipList(base_category,
- portal_type=portal_type))
+ portal_type=portal_type_list))
security.declareProtected(Permissions.AccessContentsInformation,
'checkConsistency')
@@ -71,18 +63,18 @@ class CategoryExistenceConstraint(Constr
"""
Check the object's consistency.
"""
- error_list = []
if not self.test(obj):
return []
- portal_type = self.getConstraintPortalTypeList() or ()
+ error_list = []
+ portal_type_list = self.getConstraintPortalTypeList()
# For each attribute name, we check if defined
- for base_category in self.getConstraintBaseCategoryList() or ():
+ for base_category in self.getConstraintBaseCategoryList():
mapping = dict(base_category=base_category)
# Check existence of base category
if base_category not in obj.getBaseCategoryList():
error_message = 'message_category_not_associated_with_portal_type'
- elif self._calculateArity(obj, base_category, portal_type) == 0:
+ elif self._calculateArity(obj, base_category, portal_type_list) == 0:
error_message = 'message_category_not_set'
else:
error_message = None
@@ -91,7 +83,9 @@ class CategoryExistenceConstraint(Constr
if error_message:
error_list.append(
self._generateError(obj,
- self._getMessage(error_message), mapping))
+ self._getMessage(error_message),
+ mapping))
+
return error_list
class CategoryAcquiredExistenceConstraint(CategoryExistenceConstraint):
@@ -101,6 +95,6 @@ class CategoryAcquiredExistenceConstrain
Sheets (filesystem Property Sheets rely on
Products.ERP5Type.Constraint.CategoryExistence instead).
"""
- def _calculateArity(self, obj, base_category, portal_type):
- return len(obj.getAcquiredCategoryMembershipList(base_category,
- portal_type=portal_type))
+ def _calculateArity(self, obj, base_category, portal_type_list):
+ return len(obj.getAcquiredCategoryMembershipList(
+ base_category, portal_type=portal_type_list))
Modified: erp5/trunk/products/ERP5Type/Core/ContentExistenceConstraint.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Core/ContentExistenceConstraint.py?rev=40753&r1=40752&r2=40753&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Core/ContentExistenceConstraint.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/Core/ContentExistenceConstraint.py [utf8] Fri Nov 26 08:09:08 2010
@@ -1,7 +1,8 @@
##############################################################################
#
-# Copyright (c) 2006 Nexedi SARL and Contributors. All Rights Reserved.
-# Romain Courteaud <romain at nexedi.com>
+# Copyright (c) 2006-2010 Nexedi SARL and Contributors. All Rights Reserved.
+# Romain Courteaud <romain at nexedi.com>
+# Arnaud Fontaine <arnaud.fontaine at nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
@@ -29,8 +30,6 @@
from Products.ERP5Type.mixin.constraint import ConstraintMixin
from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet
-from Products.CMFCore.Expression import Expression
-from Products.ERP5Type.Utils import createExpressionContext
class ContentExistenceConstraint(ConstraintMixin):
"""
@@ -63,14 +62,6 @@ class ContentExistenceConstraint(Constra
PropertySheet.Reference,
PropertySheet.ContentExistenceConstraint)
- # Define by default error messages
- _message_id_list = [ 'message_no_subobject',
- 'message_no_subobject_portal_type' ]
-
- message_no_subobject = "The document does not contain any subobject"
- message_no_subobject_portal_type = "The document does not contain any"\
- " subobject of portal portal type ${portal_type}"
-
def checkConsistency(self, obj, fixit=0):
"""
Checks that object contains at least one subobject and, if a list
@@ -79,8 +70,8 @@ class ContentExistenceConstraint(Constra
if not self.test(obj):
return []
- portal_type = Expression(self.getConstraintPortalType())(
- createExpressionContext(obj))
+ portal_type = self._getExpressionValue(obj,
+ self.getConstraintPortalType())
# If there is at least one subobject with the given Portal Type,
# then return now
Modified: erp5/trunk/products/ERP5Type/Core/PropertyExistenceConstraint.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Core/PropertyExistenceConstraint.py?rev=40753&r1=40752&r2=40753&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Core/PropertyExistenceConstraint.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/Core/PropertyExistenceConstraint.py [utf8] Fri Nov 26 08:09:08 2010
@@ -59,26 +59,18 @@ class PropertyExistenceConstraint(Constr
PropertySheet.Reference,
PropertySheet.PropertyExistenceConstraint)
- # Define by default error messages
- _message_id_list = ['message_no_such_property',
- 'message_property_not_set']
- message_no_such_property = "Property existence error for property "\
- "${property_id}, this document has no such property"
- message_property_not_set = "Property existence error for property "\
- "${property_id}, this property is not defined"
-
security.declareProtected(Permissions.AccessContentsInformation,
'checkConsistency')
def checkConsistency(self, obj, fixit=0):
"""
Check the object's consistency.
"""
- error_list = []
if not self.test(obj):
return []
+ error_list = []
# For each attribute name, we check if defined
- for property_id in self.getConstraintPropertyList() or ():
+ for property_id in self.getConstraintPropertyList():
# Check existence of property
mapping = dict(property_id=property_id)
if not obj.hasProperty(property_id):
@@ -91,6 +83,7 @@ class PropertyExistenceConstraint(Constr
error_message_id = None
if error_message_id:
- error_list.append(self._generateError(obj,
- self._getMessage(error_message_id), mapping))
+ error_list.append(self._generateError(
+ obj, self._getMessage(error_message_id), mapping))
+
return error_list
Modified: erp5/trunk/products/ERP5Type/PropertySheet/AttributeEqualityConstraint.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/PropertySheet/AttributeEqualityConstraint.py?rev=40753&r1=40752&r2=40753&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/PropertySheet/AttributeEqualityConstraint.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/PropertySheet/AttributeEqualityConstraint.py [utf8] Fri Nov 26 08:09:08 2010
@@ -40,8 +40,13 @@ class AttributeEqualityConstraint:
'description' : 'Valid values of the Attribute' },
{ 'id': 'message_invalid_attribute_value',
'type': 'string',
- 'description' : 'Error message when the attribute value is invalid' },
+ 'description' : 'Error message when the attribute value is invalid',
+ 'default': 'Attribute ${attribute_name} value is ${current_value} '\
+ 'but should be ${expected_value}' },
{ 'id': 'message_invalid_attribute_value_fixed',
'type': 'string',
- 'description' : 'Error message when the attribute value is invalid but has been fixed' },
+ 'description' : 'Error message when the attribute value is '\
+ 'invalid but has been fixed',
+ 'default': 'Attribute ${attribute_name} value is ${current_value} '\
+ 'but should be ${expected_value} (Fixed)'},
)
Modified: erp5/trunk/products/ERP5Type/PropertySheet/CategoryExistenceConstraint.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/PropertySheet/CategoryExistenceConstraint.py?rev=40753&r1=40752&r2=40753&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/PropertySheet/CategoryExistenceConstraint.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/PropertySheet/CategoryExistenceConstraint.py [utf8] Fri Nov 26 08:09:08 2010
@@ -33,14 +33,20 @@ class CategoryExistenceConstraint:
_properties = (
{ 'id': 'constraint_base_category',
'type': 'lines',
- 'description' : 'Categories to check the existence for' },
+ 'description' : 'Categories to check the existence for',
+ 'default': () },
{ 'id': 'constraint_portal_type',
'type': 'lines',
- 'description' : 'Portal type' },
+ 'description' : 'Portal types',
+ 'default': () },
{ 'id': 'message_category_not_set',
'type': 'string',
- 'description' : 'Error message when the category is not defined' },
+ 'description' : 'Error message when the category is not defined',
+ 'default': 'Category existence error for base category '\
+ '${base_category}, this category is not defined' },
{ 'id': 'message_category_not_associated_with_portal_type',
'type': 'string',
- 'description' : 'Error message when there is no such category' },
+ 'description' : 'Error message when there is no such category',
+ 'default': 'Category existence error for base category '\
+ '${base_category}, this document has no such category' },
)
Modified: erp5/trunk/products/ERP5Type/PropertySheet/ContentExistenceConstraint.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/PropertySheet/ContentExistenceConstraint.py?rev=40753&r1=40752&r2=40753&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/PropertySheet/ContentExistenceConstraint.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/PropertySheet/ContentExistenceConstraint.py [utf8] Fri Nov 26 08:09:08 2010
@@ -34,12 +34,16 @@ class ContentExistenceConstraint:
# TALES Expression
{ 'id': 'constraint_portal_type',
'type': 'string',
- 'description' : 'Portal type',
+ 'description' : 'Portal types',
'default': 'python: ()' },
{ 'id': 'message_no_subobject',
'type': 'string',
- 'description' : 'Error message when there is no subobject' },
+ 'description' : 'Error message when there is no subobject',
+ 'default': 'The document does not contain any subobject' },
{ 'id': 'message_no_subobject_portal_type',
'type': 'string',
- 'description' : 'Error message when there is no subobject of the given portal type' },
+ 'description' : 'Error message when there is no subobject of the '\
+ 'given portal type',
+ 'default': 'The document does not contain any subobject of portal '\
+ 'portal type ${portal_type}' },
)
Modified: erp5/trunk/products/ERP5Type/PropertySheet/PropertyExistenceConstraint.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/PropertySheet/PropertyExistenceConstraint.py?rev=40753&r1=40752&r2=40753&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/PropertySheet/PropertyExistenceConstraint.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/PropertySheet/PropertyExistenceConstraint.py [utf8] Fri Nov 26 08:09:08 2010
@@ -33,11 +33,16 @@ class PropertyExistenceConstraint:
_properties = (
{ 'id': 'constraint_property',
'type': 'lines',
- 'description' : 'Properties to check the existence for' },
+ 'description' : 'Properties to check the existence for',
+ 'default': () },
{ 'id': 'message_no_such_property',
'type': 'string',
- 'description' : 'Error message when there is no such property' },
+ 'description' : 'Error message when there is no such property',
+ 'default': 'Property existence error for property ${property_id}, '\
+ 'this document has no such property' },
{ 'id': 'message_property_not_set',
'type': 'string',
- 'description' : 'Error message when the property is not set' },
+ 'description' : 'Error message when the property is not set',
+ 'default': 'Property existence error for property ${property_id}, '\
+ 'this property is not defined' },
)
Modified: erp5/trunk/products/ERP5Type/mixin/constraint.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/mixin/constraint.py?rev=40753&r1=40752&r2=40753&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/mixin/constraint.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/mixin/constraint.py [utf8] Fri Nov 26 08:09:08 2010
@@ -35,7 +35,8 @@ from zope.interface import implements
from Products.ERP5Type.Core.Predicate import Predicate
from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions
-from Products.ERP5Type.Utils import UpperCase
+from Products.ERP5Type.Utils import UpperCase, createExpressionContext
+from Products.CMFCore.Expression import Expression
class ConstraintMixin(Predicate):
"""
@@ -54,8 +55,6 @@ class ConstraintMixin(Predicate):
__allow_access_to_unprotected_subobjects__ = 1
implements( IConstraint, )
- _message_id_list = []
-
def _getMessage(self, message_id):
"""
Get the message corresponding to this message_id.
@@ -101,3 +100,14 @@ class ConstraintMixin(Predicate):
XXX: remove as soon as the code is stable
"""
return self.asContext()
+
+ def _getExpressionValue(self, obj, expression_string):
+ """
+ Get the Python value from an Expression string, but check before
+ whether it is None as a getter may returns the default value which
+ could be None
+ """
+ if expression_string is None:
+ return None
+
+ return Expression(expression_string)(createExpressionContext(obj))
More information about the Erp5-report
mailing list