Commit e70f8534 authored by Arnaud Fontaine's avatar Arnaud Fontaine

Remove exportToFilesystemDefinitionDict in property and constraint

documents used by ZODB Property Sheets as it was only meaningful when
using Utils accessors generation which required a filesystem
definition dict


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@43961 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 80ae72de
...@@ -41,8 +41,6 @@ class AccountingTransactionBalanceConstraint(ConstraintMixin): ...@@ -41,8 +41,6 @@ class AccountingTransactionBalanceConstraint(ConstraintMixin):
meta_type = 'ERP5 Accounting Transaction Balance Constraint' meta_type = 'ERP5 Accounting Transaction Balance Constraint'
portal_type = 'Accounting Transaction Balance Constraint' portal_type = 'Accounting Transaction Balance Constraint'
__compatibility_class_name__ = 'AccountingTransactionBalance'
property_sheets = ConstraintMixin.property_sheets + \ property_sheets = ConstraintMixin.property_sheets + \
(PropertySheet.AccountingTransactionBalanceConstraint,) (PropertySheet.AccountingTransactionBalanceConstraint,)
......
...@@ -43,8 +43,6 @@ class ResourceMeasuresConsistencyConstraint(ConstraintMixin): ...@@ -43,8 +43,6 @@ class ResourceMeasuresConsistencyConstraint(ConstraintMixin):
meta_type = 'ERP5 Resource Measures Consistency Constraint' meta_type = 'ERP5 Resource Measures Consistency Constraint'
portal_type = 'Resource Measures Consistency Constraint' portal_type = 'Resource Measures Consistency Constraint'
__compatibility_class_name__ = 'ResourceMeasuresConsistency'
property_sheets = ConstraintMixin.property_sheets + \ property_sheets = ConstraintMixin.property_sheets + \
(PropertySheet.ResourceMeasuresConsistencyConstraint,) (PropertySheet.ResourceMeasuresConsistencyConstraint,)
......
...@@ -42,8 +42,6 @@ class TradeModelLineCellConsistencyConstraint(ConstraintMixin): ...@@ -42,8 +42,6 @@ class TradeModelLineCellConsistencyConstraint(ConstraintMixin):
meta_type = 'ERP5 Trade Model Line Cell Consistency Constraint' meta_type = 'ERP5 Trade Model Line Cell Consistency Constraint'
portal_type = 'Trade Model Line Cell Consistency Constraint' portal_type = 'Trade Model Line Cell Consistency Constraint'
__compatibility_class_name__ = 'TradeModelLineCellConsistency'
property_sheets = ConstraintMixin.property_sheets + \ property_sheets = ConstraintMixin.property_sheets + \
(PropertySheet.TradeModelLineCellConsistencyConstraint,) (PropertySheet.TradeModelLineCellConsistencyConstraint,)
...@@ -68,11 +66,3 @@ class TradeModelLineCellConsistencyConstraint(ConstraintMixin): ...@@ -68,11 +66,3 @@ class TradeModelLineCellConsistencyConstraint(ConstraintMixin):
@see ERP5Type.mixin.constraint.ConstraintMixin._convertFromFilesystemDefinition @see ERP5Type.mixin.constraint.ConstraintMixin._convertFromFilesystemDefinition
""" """
yield dict(base_id=base_id) yield dict(base_id=base_id)
def exportToFilesystemDefinitionDict(self):
filesystem_definition_dict = super(TradeModelLineCellConsistencyConstraint,
self).exportToFilesystemDefinitionDict()
filesystem_definition_dict['base_id'] = self.getBaseId()
return filesystem_definition_dict
...@@ -41,8 +41,6 @@ class TransactionQuantityValueFeasabilityConstraint(ConstraintMixin): ...@@ -41,8 +41,6 @@ class TransactionQuantityValueFeasabilityConstraint(ConstraintMixin):
meta_type = 'ERP5 Transaction Quantity Value Feasability Constraint' meta_type = 'ERP5 Transaction Quantity Value Feasability Constraint'
portal_type = 'Transaction Quantity Value Feasability Constraint' portal_type = 'Transaction Quantity Value Feasability Constraint'
__compatibility_class_name__ = 'TransactionQuantityValueFeasability'
def _checkConsistency(self, object, fixit=0): def _checkConsistency(self, object, fixit=0):
""" """
Check if the quantity of the transaction is possible Check if the quantity of the transaction is possible
......
...@@ -38,8 +38,6 @@ class TransactionQuantityValueValidityConstraint(ConstraintMixin): ...@@ -38,8 +38,6 @@ class TransactionQuantityValueValidityConstraint(ConstraintMixin):
meta_type = 'ERP5 Transaction Quantity Value Validity Constraint' meta_type = 'ERP5 Transaction Quantity Value Validity Constraint'
portal_type = 'Transaction Quantity Value Validity Constraint' portal_type = 'Transaction Quantity Value Validity Constraint'
__compatibility_class_name__ = 'TransactionQuantityValueValidity'
def _checkConsistency(self, object, fixit=0): def _checkConsistency(self, object, fixit=0):
""" """
Check if the quantity of the transaction is greater than the Check if the quantity of the transaction is greater than the
......
...@@ -140,42 +140,6 @@ class AcquiredProperty(StandardProperty): ...@@ -140,42 +140,6 @@ class AcquiredProperty(StandardProperty):
'content_translation_acquired_property_id', 'content_translation_acquired_property_id',
'lines') 'lines')
# TODO: remove
security.declareProtected(Permissions.AccessContentsInformation,
'exportToFilesystemDefinition')
def exportToFilesystemDefinition(self):
"""
Return the filesystem definition of this ZODB property
NOTE: Only meaningful for testing export of filesystem Property
Sheet to the ZODB
"""
filesystem_property_dict = \
StandardProperty.exportToFilesystemDefinition(self)
if filesystem_property_dict is None:
return None
acquisition_portal_type_expression = self._getExpressionFromString(
self.getAcquisitionPortalType())
portal_type_expression = self._getExpressionFromString(
self.getContentPortalType())
filesystem_property_dict.update({
'acquisition_base_category': self.getAcquisitionBaseCategoryList(),
'acquisition_object_id': self.getAcquisitionObjectIdList(),
'acquisition_portal_type': acquisition_portal_type_expression,
'acquisition_accessor_id': self.getAcquisitionAccessorId(),
'alt_accessor_id': self.getAltAccessorIdList(),
'acquisition_copy_value': self.getAcquisitionCopyValue(),
'acquisition_mask_value': self.getAcquisitionMaskValue(),
'portal_type': portal_type_expression,
'acquired_property_id': self.getContentAcquiredPropertyIdList(),
'translation_acquired_property_id': self.getContentTranslationAcquiredPropertyIdList()})
return filesystem_property_dict
@classmethod @classmethod
def _asPropertyMap(cls, property_dict): def _asPropertyMap(cls, property_dict):
""" """
......
...@@ -59,8 +59,6 @@ class AttributeEqualityConstraint(PropertyExistenceConstraint): ...@@ -59,8 +59,6 @@ class AttributeEqualityConstraint(PropertyExistenceConstraint):
meta_type = 'ERP5 Attribute Equality Constraint' meta_type = 'ERP5 Attribute Equality Constraint'
portal_type = 'Attribute Equality Constraint' portal_type = 'Attribute Equality Constraint'
__compatibility_class_name__ = 'AttributeEquality'
# Declarative security # Declarative security
security = ClassSecurityInfo() security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation) security.declareObjectProtected(Permissions.AccessContentsInformation)
...@@ -136,12 +134,3 @@ class AttributeEqualityConstraint(PropertyExistenceConstraint): ...@@ -136,12 +134,3 @@ class AttributeEqualityConstraint(PropertyExistenceConstraint):
""" """
for name, value in property_dict.iteritems(): for name, value in property_dict.iteritems():
yield dict(name=value) yield dict(name=value)
def exportToFilesystemDefinitionDict(self):
filesystem_definition_dict = super(AttributeEqualityConstraint,
self).exportToFilesystemDefinitionDict()
filesystem_definition_dict[self.getConstraintAttributeName()] = \
Expression(self.getConstraintAttributeValue())
return filesystem_definition_dict
...@@ -46,8 +46,6 @@ class CategoryExistenceConstraint(ConstraintMixin): ...@@ -46,8 +46,6 @@ class CategoryExistenceConstraint(ConstraintMixin):
meta_type = 'ERP5 Category Existence Constraint' meta_type = 'ERP5 Category Existence Constraint'
portal_type = 'Category Existence Constraint' portal_type = 'Category Existence Constraint'
__compatibility_class_name__ = 'CategoryExistence'
# Declarative security # Declarative security
security = ClassSecurityInfo() security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation) security.declareObjectProtected(Permissions.AccessContentsInformation)
...@@ -125,21 +123,3 @@ class CategoryExistenceConstraint(ConstraintMixin): ...@@ -125,21 +123,3 @@ class CategoryExistenceConstraint(ConstraintMixin):
yield dict(constraint_base_category_list=base_category_dict.keys(), yield dict(constraint_base_category_list=base_category_dict.keys(),
constraint_portal_type=constraint_portal_type_str) constraint_portal_type=constraint_portal_type_str)
def exportToFilesystemDefinitionDict(self):
filesystem_definition_dict = super(CategoryExistenceConstraint,
self).exportToFilesystemDefinitionDict()
# There is only one ZODB Constraint class for filesystem
# Constraints CategoryExistence and CategoryAcquiredExistence
# constraints
if self.getUseAcquisition():
filesystem_definition_dict['type'] = 'CategoryAcquiredExistence'
filesystem_definition_dict['portal_type'] = \
Expression(self.getConstraintPortalType())
for category in self.getConstraintBaseCategoryList():
filesystem_definition_dict[category] = 1
return filesystem_definition_dict
...@@ -54,8 +54,6 @@ class CategoryMembershipArityConstraint(ConstraintMixin): ...@@ -54,8 +54,6 @@ class CategoryMembershipArityConstraint(ConstraintMixin):
meta_type = 'ERP5 Category Membership Arity Constraint' meta_type = 'ERP5 Category Membership Arity Constraint'
portal_type = 'Category Membership Arity Constraint' portal_type = 'Category Membership Arity Constraint'
__compatibility_class_name__ = 'CategoryMembershipArity'
# Declarative security # Declarative security
security = ClassSecurityInfo() security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation) security.declareObjectProtected(Permissions.AccessContentsInformation)
...@@ -160,25 +158,3 @@ class CategoryMembershipArityConstraint(ConstraintMixin): ...@@ -160,25 +158,3 @@ class CategoryMembershipArityConstraint(ConstraintMixin):
zodb_property_dict['max_arity'] = int(max_arity) zodb_property_dict['max_arity'] = int(max_arity)
yield zodb_property_dict yield zodb_property_dict
def exportToFilesystemDefinitionDict(self):
filesystem_definition_dict = super(CategoryMembershipArityConstraint,
self).exportToFilesystemDefinitionDict()
# There is only one ZODB Constraint class for filesystem
# Constraints CategoryMembershipArity and
# CategoryAcquiredMembershipArity constraints
if self.getUseAcquisition():
filesystem_definition_dict['type'] = 'CategoryAcquiredMembershipArity'
filesystem_definition_dict['min_arity'] = str(self.getMinArity())
if self.hasMaxArity():
filesystem_definition_dict['max_arity'] = str(self.getMaxArity())
filesystem_definition_dict['portal_type'] = \
Expression(self.getConstraintPortalType())
filesystem_definition_dict['base_category'] = self.getConstraintBaseCategoryList()
return filesystem_definition_dict
...@@ -51,15 +51,6 @@ class CategoryProperty(IdAsReferenceMixin('_category'), XMLObject): ...@@ -51,15 +51,6 @@ class CategoryProperty(IdAsReferenceMixin('_category'), XMLObject):
property_sheets = (PropertySheet.SimpleItem, property_sheets = (PropertySheet.SimpleItem,
PropertySheet.Reference) PropertySheet.Reference)
# TODO: REMOVE
security.declareProtected(Permissions.AccessContentsInformation,
'exportToFilesystemDefinition')
def exportToFilesystemDefinition(self):
"""
Return the filesystem definition of the property
"""
return self.getReference()
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'importFromFilesystemDefinition') 'importFromFilesystemDefinition')
@classmethod @classmethod
......
...@@ -58,8 +58,6 @@ class CategoryRelatedMembershipArityConstraint(CategoryMembershipArityConstraint ...@@ -58,8 +58,6 @@ class CategoryRelatedMembershipArityConstraint(CategoryMembershipArityConstraint
meta_type = 'ERP5 Category Related Membership Arity Constraint' meta_type = 'ERP5 Category Related Membership Arity Constraint'
portal_type = 'Category Related Membership Arity Constraint' portal_type = 'Category Related Membership Arity Constraint'
__compatibility_class_name__ = 'CategoryRelatedMembershipArity'
property_sheets = CategoryMembershipArityConstraint.property_sheets + \ property_sheets = CategoryMembershipArityConstraint.property_sheets + \
(PropertySheet.CategoryRelatedMembershipArityConstraint,) (PropertySheet.CategoryRelatedMembershipArityConstraint,)
......
...@@ -54,8 +54,6 @@ class ContentExistenceConstraint(ConstraintMixin): ...@@ -54,8 +54,6 @@ class ContentExistenceConstraint(ConstraintMixin):
meta_type = 'ERP5 Content Existence Constraint' meta_type = 'ERP5 Content Existence Constraint'
portal_type = 'Content Existence Constraint' portal_type = 'Content Existence Constraint'
__compatibility_class_name__ = 'ContentExistence'
# Declarative security # Declarative security
security = ClassSecurityInfo() security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation) security.declareObjectProtected(Permissions.AccessContentsInformation)
...@@ -110,12 +108,3 @@ class ContentExistenceConstraint(ConstraintMixin): ...@@ -110,12 +108,3 @@ class ContentExistenceConstraint(ConstraintMixin):
portal_type.text or 'python: ' + repr(portal_type) portal_type.text or 'python: ' + repr(portal_type)
yield dict(constraint_portal_type=constraint_portal_type_str) yield dict(constraint_portal_type=constraint_portal_type_str)
def exportToFilesystemDefinitionDict(self):
filesystem_definition_dict = super(ContentExistenceConstraint,
self).exportToFilesystemDefinitionDict()
filesystem_definition_dict['portal_type'] = \
Expression(self.getConstraintPortalType())
return filesystem_definition_dict
...@@ -50,19 +50,6 @@ class DynamicCategoryProperty(CategoryProperty): ...@@ -50,19 +50,6 @@ class DynamicCategoryProperty(CategoryProperty):
property_sheets = (PropertySheet.SimpleItem, property_sheets = (PropertySheet.SimpleItem,
PropertySheet.DynamicCategoryProperty) PropertySheet.DynamicCategoryProperty)
# TODO: REMOVE
security.declareProtected(Permissions.AccessContentsInformation,
'exportToFilesystemDefinition')
def exportToFilesystemDefinition(self):
"""
Return the filesystem definition of the property
"""
expression_string = self.getCategoryExpression()
if expression_string is None:
return None
return Expression(expression_string)
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'importFromFilesystemDefinition') 'importFromFilesystemDefinition')
@classmethod @classmethod
......
...@@ -50,8 +50,6 @@ class PropertyExistenceConstraint(ConstraintMixin): ...@@ -50,8 +50,6 @@ class PropertyExistenceConstraint(ConstraintMixin):
meta_type = 'ERP5 Property Existence Constraint' meta_type = 'ERP5 Property Existence Constraint'
portal_type = 'Property Existence Constraint' portal_type = 'Property Existence Constraint'
__compatibility_class_name__ = 'PropertyExistence'
# Declarative security # Declarative security
security = ClassSecurityInfo() security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation) security.declareObjectProtected(Permissions.AccessContentsInformation)
...@@ -113,12 +111,3 @@ class PropertyExistenceConstraint(ConstraintMixin): ...@@ -113,12 +111,3 @@ class PropertyExistenceConstraint(ConstraintMixin):
} }
""" """
yield dict(constraint_property_list=property_dict.keys()) yield dict(constraint_property_list=property_dict.keys())
def exportToFilesystemDefinitionDict(self):
filesystem_definition_dict = super(PropertyExistenceConstraint,
self).exportToFilesystemDefinitionDict()
for constraint_property in self.getConstraintPropertyList():
filesystem_definition_dict[constraint_property] = None
return filesystem_definition_dict
...@@ -48,44 +48,6 @@ class PropertySheet(Folder): ...@@ -48,44 +48,6 @@ class PropertySheet(Folder):
security = ClassSecurityInfo() security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation) security.declareObjectProtected(Permissions.AccessContentsInformation)
# TODO: REMOVE
security.declareProtected(Permissions.AccessContentsInformation,
'exportToFilesystemDefinition')
def exportToFilesystemDefinition(self):
"""
Export the ZODB Property Sheet to its filesystem definition as a
tuple (properties, categories, constraints)
"""
properties = []
constraints = []
categories = []
for item in self.contentValues():
definition = item.exportToFilesystemDefinition()
# If a category doesn't have a name yet or the constraint class
# returned is None, then just skip it
if definition is None:
LOG("ERP5Type.Core.PropertySheet", INFO,
"Skipping property with ID '%s' in Property Sheet '%s'" % \
(item.getId(), self.getId()))
continue
portal_type = item.getPortalType()
if portal_type == "Category Property" or \
portal_type == "Dynamic Category Property":
categories.append(definition)
elif portal_type.endswith('Constraint'):
constraints.append(definition)
else:
properties.append(definition)
return (properties, categories, constraints)
security.declarePrivate('createAccessorHolder') security.declarePrivate('createAccessorHolder')
def createAccessorHolder(self, expression_context, portal): def createAccessorHolder(self, expression_context, portal):
""" """
......
...@@ -44,8 +44,6 @@ class PropertyTypeValidityConstraint(ConstraintMixin): ...@@ -44,8 +44,6 @@ class PropertyTypeValidityConstraint(ConstraintMixin):
meta_type = 'ERP5 Property Type Validity Constraint' meta_type = 'ERP5 Property Type Validity Constraint'
portal_type = 'Property Type Validity Constraint' portal_type = 'Property Type Validity Constraint'
__compatibility_class_name__ = 'PropertyTypeValidity'
property_sheets = ConstraintMixin.property_sheets + \ property_sheets = ConstraintMixin.property_sheets + \
(PropertySheet.PropertyTypeValidityConstraint,) (PropertySheet.PropertyTypeValidityConstraint,)
......
...@@ -131,44 +131,6 @@ class StandardProperty(IdAsReferenceMixin('_property'), XMLObject): ...@@ -131,44 +131,6 @@ class StandardProperty(IdAsReferenceMixin('_property'), XMLObject):
'translation_domain', 'translation_domain',
'string') 'string')
# TODO: REMOVE
@staticmethod
def _getExpressionFromString(expression_string):
"""
Get a TALES Expression instance from a string value
"""
if expression_string is None:
return None
return Expression(expression_string)
# TODO: REMOVE
security.declareProtected(Permissions.AccessContentsInformation,
'exportToFilesystemDefinition')
def exportToFilesystemDefinition(self):
"""
Return the filesystem definition of this ZODB property
NOTE: Only meaningful for testing export of filesystem Property
Sheet to the ZODB
"""
property_default_value = self._getExpressionFromString(self.getPropertyDefault())
reference = self.getReference()
if reference:
return {'id': reference,
'description': self.getDescription(),
'type': self.getElementaryType(),
'storage_id': self.getStorageId(),
'multivalued': self.getMultivalued(),
'default': property_default_value,
'range': self.getRange(),
'preference': self.getPreference(),
'read_permission': self.getReadPermission(),
'write_permission': self.getWritePermission(),
'translatable': self.getTranslatable(),
'translation_domain': self.getTranslationDomain()}
@classmethod @classmethod
def _asPropertyMap(cls, property_dict): def _asPropertyMap(cls, property_dict):
""" """
......
...@@ -61,8 +61,6 @@ class TALESConstraint(ConstraintMixin): ...@@ -61,8 +61,6 @@ class TALESConstraint(ConstraintMixin):
meta_type = 'ERP5 TALES Constraint' meta_type = 'ERP5 TALES Constraint'
portal_type = 'TALES Constraint' portal_type = 'TALES Constraint'
__compatibility_class_name__ = 'TALESConstraint'
property_sheets = ConstraintMixin.property_sheets + \ property_sheets = ConstraintMixin.property_sheets + \
(PropertySheet.TALESConstraint,) (PropertySheet.TALESConstraint,)
...@@ -95,11 +93,3 @@ class TALESConstraint(ConstraintMixin): ...@@ -95,11 +93,3 @@ class TALESConstraint(ConstraintMixin):
@staticmethod @staticmethod
def _convertFromFilesystemDefinition(expression): def _convertFromFilesystemDefinition(expression):
yield dict(expression=expression) yield dict(expression=expression)
def exportToFilesystemDefinitionDict(self):
filesystem_definition_dict = super(TALESConstraint,
self).exportToFilesystemDefinitionDict()
filesystem_definition_dict['expression'] = self.getExpression()
return filesystem_definition_dict
...@@ -57,11 +57,6 @@ class ConstraintMixin(IdAsReferenceMixin('_constraint'), Predicate): ...@@ -57,11 +57,6 @@ class ConstraintMixin(IdAsReferenceMixin('_constraint'), Predicate):
# importing or exporting from/to filesystem Constraint # importing or exporting from/to filesystem Constraint
_message_id_tuple = () _message_id_tuple = ()
# Store the filesystem name of the ZODB Constraint as there are
# several different naming for filesystem constraints (*only* useful
# for exportToFilesystemDefinitionDict)
__compatibility_class_name__ = None
__allow_access_to_unprotected_subobjects__ = 1 __allow_access_to_unprotected_subobjects__ = 1
implements( IConstraint, ) implements( IConstraint, )
...@@ -106,27 +101,6 @@ class ConstraintMixin(IdAsReferenceMixin('_constraint'), Predicate): ...@@ -106,27 +101,6 @@ class ConstraintMixin(IdAsReferenceMixin('_constraint'), Predicate):
""" """
return self.checkConsistency(obj, fixit=1, **kw) return self.checkConsistency(obj, fixit=1, **kw)
security.declareProtected(Permissions.AccessContentsInformation,
'exportToFilesystemDefinition')
def exportToFilesystemDefinition(self):
"""
Return a temporary copy of the constraint object (with acquisition
wrapping removed) in order to maintain compatibility and be able
to use setDefaultProperties
NOTE: A filesystem constraint is defined by a dict, then depending
on the 'type' of the constraint, the appropriate class in
ERP5Type.Constraint is instanciated with the dict. This is no
longer needed for ZODB Constraints because they are already
Documents.
@see exportToFilesystemDefinitionDict() to export a ZODB
Constraint as a dict.
XXX: remove as soon as the code is stable
"""
return self.asContext().aq_base
def _getExpressionValue(self, obj, expression_string): def _getExpressionValue(self, obj, expression_string):
""" """
Get the Python value from an Expression string, but check before Get the Python value from an Expression string, but check before
...@@ -219,29 +193,6 @@ class ConstraintMixin(IdAsReferenceMixin('_constraint'), Predicate): ...@@ -219,29 +193,6 @@ class ConstraintMixin(IdAsReferenceMixin('_constraint'), Predicate):
constraint_definition_dict.update(base_constraint_definition_dict) constraint_definition_dict.update(base_constraint_definition_dict)
context.newContent(**constraint_definition_dict) context.newContent(**constraint_definition_dict)
security.declareProtected(Permissions.AccessContentsInformation,
'exportToFilesystemDefinitionDict')
def exportToFilesystemDefinitionDict(self):
"""
Export the ZODB Constraint as a filesystem definition dict,
meaningful *only* for testing that a filesystem Constraint has
been properly converted
@see exportToFilesystemDefinition()
"""
filesystem_definition_dict = dict(
id=self.getReference(),
description=self.getDescription(),
type=self.__compatibility_class_name__)
if self.hasTestTalesExpression():
filesystem_definition_dict['condition'] = self.getTestTalesExpression()
for message_id in self._message_id_tuple:
filesystem_definition_dict[message_id] = self._getMessage(message_id)
return filesystem_definition_dict
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'applyOnAccessorHolder') 'applyOnAccessorHolder')
def applyOnAccessorHolder(self, accessor_holder, expression_context, portal): def applyOnAccessorHolder(self, accessor_holder, expression_context, portal):
......
...@@ -1107,228 +1107,6 @@ class TestZodbPropertySheet(ERP5TypeTestCase): ...@@ -1107,228 +1107,6 @@ class TestZodbPropertySheet(ERP5TypeTestCase):
self.fail("Creating a Category Expression with syntax error raises "\ self.fail("Creating a Category Expression with syntax error raises "\
"an error") "an error")
from Products.CMFCore.Expression import Expression
class TestZodbImportFilesystemPropertySheet(ERP5TypeTestCase):
"""
Check that importing filesystem Property Sheets into ZODB the same
properties and their values
"""
# The following fields of properties are no longer defined in ZODB
# Property Sheets because they have been deprecated
deprecated_field_name_tuple = ('mode',
'select_variable',
'label',
'acquisition_depends',
'acquisition_sync_value')
def afterSetUp(self):
# Mapping between the field name of a property and the default
# value as defined in StandardProperty and AcquiredProperty,
# meaningful because exporting a property relies on accessor which
# returns the default value if the field value is not set
self.filesystem_field_default_value_dict = {}
from Products.ERP5Type.PropertySheet import StandardProperty, AcquiredProperty
for property_dict in StandardProperty._properties + AcquiredProperty._properties:
try:
self.filesystem_field_default_value_dict[property_dict['id']] = \
property_dict['default']
except KeyError:
# Some fields may not defined a default value (such as 'id')
continue
def _checkPropertyOrConstraintField(self,
property_sheet_name,
field_name,
filesystem_value,
zodb_value):
"""
Check whether the given filesystem property or constraint value
and the given ZODB property value are equal
"""
if isinstance(zodb_value, (list, tuple)) and \
isinstance(filesystem_value, (list, tuple)):
self.failIfDifferentSet(
zodb_value, filesystem_value,
msg="%s: %s: filesystem value: %s, ZODB value: %s" % \
(property_sheet_name, field_name, filesystem_value, zodb_value))
else:
# In ZODB Property Sheets, we have to get the TALES Expression
# as a string for properties, which used to be Expression in
# filesystem Property Sheets or are now Expression (because they
# used to be defined as Python types, such as tuple or int...)
if isinstance(zodb_value, Expression):
# In filesystem Property Sheets, acquisition_portal_type and
# portal_type, might be instances of Expression
if isinstance(filesystem_value, Expression):
zodb_value = zodb_value.text
filesystem_value = filesystem_value.text
# Otherwise, just convert the filesystem value to a TALES
# Expression string
else:
zodb_value = zodb_value.text
filesystem_value = 'python: ' + repr(filesystem_value)
self.failUnlessEqual(
zodb_value, filesystem_value,
msg="%s: %s: filesystem value: %s, ZODB value: %s" % \
(property_sheet_name, field_name, filesystem_value,
zodb_value))
def _checkPropertyOrConstraintDefinitionTuple(self,
property_sheet_name,
filesystem_property_tuple,
zodb_property_tuple):
"""
Check whether all properties or constraints have been properly
converted from the filesystem to the ZODB Property Sheet
"""
# Check whether all the properties or constraints are present in
# the given ZODB Property Sheet
self.assertEqual(
len(filesystem_property_tuple), len(zodb_property_tuple),
msg="%s: too many properties: filesystem: %s, ZODB: %s" % \
(property_sheet_name, filesystem_property_tuple, zodb_property_tuple))
# Map filesystem property or constraint IDs to their definition
filesystem_property_id_dict = {}
for property_dict in filesystem_property_tuple:
filesystem_property_id_dict[property_dict['id']] = property_dict
# Check each property or constraint defined in ZODB against the
# filesystem dict defined before
for zodb_property_dict in zodb_property_tuple:
# Meaningful to ensure that there is no missing field within a
# property or constraint
validated_field_counter = 0
filesystem_property_dict = \
filesystem_property_id_dict[zodb_property_dict['id']]
# Check each property or constraint field
for field_name, zodb_value in zodb_property_dict.iteritems():
if field_name in filesystem_property_dict:
self._checkPropertyOrConstraintField(
property_sheet_name, field_name,
filesystem_property_dict[field_name],
zodb_value)
# As we are using accessors when exporting the ZODB Property
# Sheet to its filesystem definition, there may be additional
# fields set to their default value
elif field_name in self.filesystem_field_default_value_dict:
self.assertEqual(
self.filesystem_field_default_value_dict[field_name],
zodb_value,
msg="%s: Wrong default value %s for %s" % \
(property_sheet_name, zodb_value, field_name))
validated_field_counter += 1
if len(filesystem_property_dict) != validated_field_counter:
missing_field_name_list = [
k for k in filesystem_property_dict \
if k not in zodb_property_dict and \
k not in self.deprecated_field_name_tuple ]
self.assertTrue(
len(missing_field_name_list) == 0,
msg="%s: missing fields: %s: filesystem: %s, ZODB: %s" % \
(property_sheet_name, missing_field_name_list,
filesystem_property_dict, zodb_property_dict))
def _checkCategoryTuple(self,
property_sheet_name,
filesystem_category_tuple,
zodb_category_tuple):
"""
Check whether all categories have been properly converted
"""
# There should be the same number of categories
self.assertEqual(
len(filesystem_category_tuple), len(zodb_category_tuple),
msg="%s: Missing/added categories: filesystem: %s, ZODB: %s" % \
(property_sheet_name, filesystem_category_tuple, zodb_category_tuple))
# Some Categories are instance of Expression, so compute a list of
# categories as strings
zodb_category_list = [
isinstance(category, Expression) and category.text or category \
for category in zodb_category_tuple ]
# Now, compare filesystem categories with ZODB
for category in filesystem_category_tuple:
if isinstance(category, Expression):
category = category.text
self.assertTrue(
category in zodb_category_list,
msg="%s: Missing category %s: ZODB: %s" % \
(property_sheet_name, category, zodb_category_list))
def testZodbImportPropertySheet(self):
"""
Create Property Sheets on portal_property_sheets from their
definition on the filesystem and then test that they are
equivalent
"""
portal = self.getPortalObject().portal_property_sheets
from Products.ERP5PropertySheetLegacy import PropertySheet
import os
property_sheets_tool = self.portal.portal_property_sheets
property_sheet_legacy_class_dict = {}
for module in os.listdir(os.path.dirname(PropertySheet.__file__)):
if module == '__init__.py' or module[-3:] != '.py':
continue
filename = module[:-3]
property_sheet_legacy_class_dict[filename] = \
getattr(__import__(filename, locals(), globals()), filename)
# Get all the property sheets defined on the filesystem
for name, klass in property_sheet_legacy_class_dict.iteritems():
filesystem_property_sheet = klass
property_sheet_name = name
# Rename the filesystem Property Sheet class to avoid clashing
# with existing Property Sheets in portal_property_sheets
filesystem_property_sheet.__name__ = "%s_%s" % \
(self.__class__.__name__, property_sheet_name)
zodb_property_sheet = PropertySheetDocument.importFromFilesystemDefinition(
property_sheets_tool, filesystem_property_sheet)
self.assertTrue(filesystem_property_sheet.__name__ in \
property_sheets_tool.objectIds())
zodb_property_tuple, zodb_category_tuple, zodb_constraint_class_tuple = \
zodb_property_sheet.exportToFilesystemDefinition()
self._checkPropertyOrConstraintDefinitionTuple(
property_sheet_name,
getattr(filesystem_property_sheet, '_properties', []),
zodb_property_tuple)
self._checkCategoryTuple(property_sheet_name,
getattr(filesystem_property_sheet,
'_categories', []),
zodb_category_tuple)
self._checkPropertyOrConstraintDefinitionTuple(
property_sheet_name, getattr(filesystem_property_sheet,
'_constraints', []),
[ zodb_constraint_class.exportToFilesystemDefinitionDict() \
for zodb_constraint_class in zodb_constraint_class_tuple ])
TestZodbImportFilesystemPropertySheet = skip(
"ERP5PropertySheetLegacy is now obsolete")(
TestZodbImportFilesystemPropertySheet)
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestPortalTypeClass)) suite.addTest(unittest.makeSuite(TestPortalTypeClass))
......
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