diff --git a/product/ERP5Type/Core/AcquiredProperty.py b/product/ERP5Type/Core/AcquiredProperty.py index b04bf2502b4fc92aa22b1551fb24fcb486eaa364..0793280afb2d5cdd0534646be5808d9ba13788d9 100644 --- a/product/ERP5Type/Core/AcquiredProperty.py +++ b/product/ERP5Type/Core/AcquiredProperty.py @@ -28,9 +28,10 @@ from AccessControl import ClassSecurityInfo from Products.CMFCore.Expression import Expression - from Products.ERP5Type import Permissions, PropertySheet from Products.ERP5Type.Core.StandardProperty import StandardProperty +from Products.ERP5Type.Accessor.Base import Getter as BaseGetter +from Products.ERP5Type.Accessor.List import ListGetter class AcquiredProperty(StandardProperty): """ @@ -62,16 +63,61 @@ class AcquiredProperty(StandardProperty): StandardProperty._expression_attribute_tuple + \ ('acquisition_portal_type', 'content_portal_type') - @staticmethod - def _convertValueToTalesExpression(value): - """ - Convert a string value to a TALES expression for attributes listed - in '_expression_attribute_tuple' - """ - if value is None: - return None + # Define getters for the property. This is necessary for bootstrap + # as a Standard Property uses SimpleItem, defined with Acquired + # Properties + # + # There is no need to define the setter as this static definition of + # the getter is only meaningful for the Acquired Properties defined + # within an Acquired Property. + getAcquisitionBaseCategoryList = ListGetter( + 'getAcquisitionBaseCategoryList', + 'acquisition_base_category', + 'lines') + + getAcquisitionObjectIdList = ListGetter('getAcquisitionObjectIdList', + 'acquisition_object_id', + 'lines') + + # Use a tales type here, so the TALES expression instance is created + # when actually calling the function + getAcquisitionPortalType = BaseGetter('getAcquisitionPortalType', + 'acquisition_portal_type', + 'tales') + + getAcquisitionAccessorId = BaseGetter('getAcquisitionAccessorId', + 'acquisition_accessor_id', + 'string') + + getAltAccessorIdList = ListGetter('getAltAccessorIdList', + 'alt_accessor_id', + 'lines') + + getAcquisitionCopyValue = BaseGetter('getAcquisitionCopyValue', + 'acquisition_copy_value', + 'boolean', + default=False) + + getAcquisitionMaskValue = BaseGetter('getAcquisitionMaskValue', + 'acquisition_mask_value', + 'boolean', + default=False) + + # Use a tales type here, so the TALES expression instance is created + # when actually calling the function + getContentPortalType = BaseGetter('getContentPortalType', + 'content_portal_type', + 'tales') + + getContentAcquiredPropertyIdList = ListGetter( + 'getContentAcquiredPropertyIdList', + 'content_acquired_property_id', + 'lines') - return Expression(value) + getContentTranslationAcquiredPropertyIdList = ListGetter( + 'getContentTranslationAcquiredPropertyIdList', + 'content_translation_acquired_property_id', + 'lines') security.declareProtected(Permissions.AccessContentsInformation, 'exportToFilesystemDefinition') @@ -85,12 +131,12 @@ class AcquiredProperty(StandardProperty): filesystem_property_dict.update( {'acquisition_base_category': self.getAcquisitionBaseCategoryList(), 'acquisition_object_id': self.getAcquisitionObjectIdList(), - 'acquisition_portal_type': self._convertValueToTalesExpression(self.getAcquisitionPortalType()), + 'acquisition_portal_type': self.getAcquisitionPortalType(), 'acquisition_accessor_id': self.getAcquisitionAccessorId(), 'alt_accessor_id': self.getAltAccessorIdList(), 'acquisition_copy_value': self.getAcquisitionCopyValue(), 'acquisition_mask_value': self.getAcquisitionMaskValue(), - 'portal_type': self._convertValueToTalesExpression(self.getContentPortalType()), + 'portal_type': self.getContentPortalType(), 'acquired_property_id': self.getContentAcquiredPropertyIdList(), 'translation_acquired_property_id': self.getContentTranslationAcquiredPropertyIdList()}) diff --git a/product/ERP5Type/Core/CategoryProperty.py b/product/ERP5Type/Core/CategoryProperty.py index f5239aaad130870e7e4d306f65eebb60f5d1726b..438970c3547b4a13286011441ccba9788c17e85d 100644 --- a/product/ERP5Type/Core/CategoryProperty.py +++ b/product/ERP5Type/Core/CategoryProperty.py @@ -29,6 +29,7 @@ from AccessControl import ClassSecurityInfo from Products.ERP5Type import Permissions, PropertySheet from Products.ERP5Type.XMLObject import XMLObject +from Products.ERP5Type.Accessor.Base import Getter as BaseGetter class CategoryProperty(XMLObject): """ @@ -44,6 +45,9 @@ class CategoryProperty(XMLObject): property_sheets = (PropertySheet.SimpleItem, PropertySheet.Reference) + getReference = BaseGetter('getReference', 'reference', 'string', + storage_id='default_reference') + security.declareProtected(Permissions.AccessContentsInformation, 'exportToFilesystemDefinition') def exportToFilesystemDefinition(self): diff --git a/product/ERP5Type/Core/StandardProperty.py b/product/ERP5Type/Core/StandardProperty.py index c619036415b3f60d948cbaed1c821d469f78ad6d..a2b7ffef619b854cebe964cb15095266a057c783 100644 --- a/product/ERP5Type/Core/StandardProperty.py +++ b/product/ERP5Type/Core/StandardProperty.py @@ -28,9 +28,9 @@ from AccessControl import ClassSecurityInfo from Products.CMFCore.Expression import Expression - from Products.ERP5Type import Permissions, PropertySheet from Products.ERP5Type.XMLObject import XMLObject +from Products.ERP5Type.Accessor.Base import Getter as BaseGetter class StandardProperty(XMLObject): """ @@ -57,6 +57,61 @@ class StandardProperty(XMLObject): # ZODB name of attributes whose value is a TALES Expression string _expression_attribute_tuple = ('property_default',) + # Define getters for the property. This is necessary for bootstrap + # as a Standard Property is defined by Standard Properties which + # also depends on Property Sheets defined by Standard Properties. + # + # There is no need to define the setter as this static definition of + # the getter is only meaningful for the Standard Properties defined + # within an Standard Property. + getReference = BaseGetter('getReference', 'reference', 'string', + storage_id='default_reference') + + getDescription = BaseGetter('getDescription', 'description', 'string', + default='') + + def getElementaryType(self): + """ + Define this getter manually as it is not possible to rely on + CategoryTool during the bootstrap + """ + for category in self.__dict__.get('categories', ()): + if category.startswith('elementary_type/'): + return category.split('elementary_type/')[1] + + raise AttributeError("%s: Could not get elementary_type" % self) + + getStorageId = BaseGetter('getStorageId', 'storage_id', 'string') + + getMultivalued = BaseGetter('getMultivalued', 'multivalued', 'boolean', + default=False) + + # Use a tales type here, so the TALES expression instance is created + # when actually calling the function + getPropertyDefault = BaseGetter('getPropertyDefault', 'property_default', + 'tales') + + getRange = BaseGetter('getRange', 'range', 'boolean', default=False) + + getPreference = BaseGetter('getPreference', 'preference', 'boolean', + default=False) + + getReadPermission = BaseGetter( + 'getReadPermission', 'read_permission', 'string', + default=Permissions.AccessContentsInformation) + + getWritePermission = BaseGetter('getWritePermission', + 'write_permission', + 'string', + default=Permissions.ModifyPortalContent) + + getTranslatable = BaseGetter('getTranslatable', 'translatable', 'boolean', + default=False) + + getTranslationDomain = BaseGetter('getTranslationDomain', + 'translation_domain', + 'string') + security.declareProtected(Permissions.AccessContentsInformation, 'exportToFilesystemDefinition') def exportToFilesystemDefinition(self): @@ -68,7 +123,7 @@ class StandardProperty(XMLObject): 'type': self.getElementaryType(), 'storage_id': self.getStorageId(), 'multivalued': self.getMultivalued(), - 'default': Expression(self.getPropertyDefault()), + 'default': self.getPropertyDefault(), 'range': self.getRange(), 'preference': self.getPreference(), 'read_permission': self.getReadPermission(),