Commit be364214 authored by Arnaud Fontaine's avatar Arnaud Fontaine

Add static getters for StandardProperty, AcquiredProperty and

CategoryProperty documents for bootstrap with only ZODB Property
Sheets.



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@39941 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 3afe785c
......@@ -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()})
......
......@@ -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):
......
......@@ -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(),
......
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