Commit 377b34e3 authored by Arnaud Fontaine's avatar Arnaud Fontaine

Fix TALES property getters for ZODB Property Sheets.

These getters must return a string rather than the evaluated
Expression, otherwise it means that only the result of the Expression
is displayed in the view rather than the TALES Expression itself.



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@40224 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 06718775
...@@ -79,11 +79,12 @@ class AcquiredProperty(StandardProperty): ...@@ -79,11 +79,12 @@ class AcquiredProperty(StandardProperty):
'acquisition_object_id', 'acquisition_object_id',
'lines') 'lines')
# Use a tales type here, so the TALES expression instance is created # Define as a TALES expression string, use for Expression
# when actually calling the function # instanciation when exporting the property to the filesystem
# definition
getAcquisitionPortalType = BaseGetter('getAcquisitionPortalType', getAcquisitionPortalType = BaseGetter('getAcquisitionPortalType',
'acquisition_portal_type', 'acquisition_portal_type',
'tales') 'string')
getAcquisitionAccessorId = BaseGetter('getAcquisitionAccessorId', getAcquisitionAccessorId = BaseGetter('getAcquisitionAccessorId',
'acquisition_accessor_id', 'acquisition_accessor_id',
...@@ -103,11 +104,12 @@ class AcquiredProperty(StandardProperty): ...@@ -103,11 +104,12 @@ class AcquiredProperty(StandardProperty):
'boolean', 'boolean',
default=False) default=False)
# Use a tales type here, so the TALES expression instance is created # Define as a TALES expression string, use for Expression
# when actually calling the function # instanciation when exporting the property to the filesystem
# definition
getContentPortalType = BaseGetter('getContentPortalType', getContentPortalType = BaseGetter('getContentPortalType',
'content_portal_type', 'content_portal_type',
'tales') 'string')
getContentAcquiredPropertyIdList = ListGetter( getContentAcquiredPropertyIdList = ListGetter(
'getContentAcquiredPropertyIdList', 'getContentAcquiredPropertyIdList',
...@@ -128,15 +130,21 @@ class AcquiredProperty(StandardProperty): ...@@ -128,15 +130,21 @@ class AcquiredProperty(StandardProperty):
filesystem_property_dict = \ filesystem_property_dict = \
StandardProperty.exportToFilesystemDefinition(self) StandardProperty.exportToFilesystemDefinition(self)
acquisition_portal_type_value = self._convertValueToTalesExpression(
self.getAcquisitionPortalType())
portal_type_value = self._convertValueToTalesExpression(
self.getContentPortalType())
filesystem_property_dict.update( filesystem_property_dict.update(
{'acquisition_base_category': self.getAcquisitionBaseCategoryList(), {'acquisition_base_category': self.getAcquisitionBaseCategoryList(),
'acquisition_object_id': self.getAcquisitionObjectIdList(), 'acquisition_object_id': self.getAcquisitionObjectIdList(),
'acquisition_portal_type': self.getAcquisitionPortalType(), 'acquisition_portal_type': acquisition_portal_type_value,
'acquisition_accessor_id': self.getAcquisitionAccessorId(), 'acquisition_accessor_id': self.getAcquisitionAccessorId(),
'alt_accessor_id': self.getAltAccessorIdList(), 'alt_accessor_id': self.getAltAccessorIdList(),
'acquisition_copy_value': self.getAcquisitionCopyValue(), 'acquisition_copy_value': self.getAcquisitionCopyValue(),
'acquisition_mask_value': self.getAcquisitionMaskValue(), 'acquisition_mask_value': self.getAcquisitionMaskValue(),
'portal_type': self.getContentPortalType(), 'portal_type': portal_type_value,
'acquired_property_id': self.getContentAcquiredPropertyIdList(), 'acquired_property_id': self.getContentAcquiredPropertyIdList(),
'translation_acquired_property_id': self.getContentTranslationAcquiredPropertyIdList()}) 'translation_acquired_property_id': self.getContentTranslationAcquiredPropertyIdList()})
......
...@@ -86,10 +86,11 @@ class StandardProperty(XMLObject): ...@@ -86,10 +86,11 @@ class StandardProperty(XMLObject):
getMultivalued = BaseGetter('getMultivalued', 'multivalued', 'boolean', getMultivalued = BaseGetter('getMultivalued', 'multivalued', 'boolean',
default=False) default=False)
# Use a tales type here, so the TALES expression instance is created # Define as a TALES expression string, use for Expression
# when actually calling the function # instanciation when exporting the property to the filesystem
# definition
getPropertyDefault = BaseGetter('getPropertyDefault', 'property_default', getPropertyDefault = BaseGetter('getPropertyDefault', 'property_default',
'tales') 'string')
getRange = BaseGetter('getRange', 'range', 'boolean', default=False) getRange = BaseGetter('getRange', 'range', 'boolean', default=False)
...@@ -112,18 +113,32 @@ class StandardProperty(XMLObject): ...@@ -112,18 +113,32 @@ class StandardProperty(XMLObject):
'translation_domain', 'translation_domain',
'string') 'string')
@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
return Expression(value)
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'exportToFilesystemDefinition') 'exportToFilesystemDefinition')
def exportToFilesystemDefinition(self): def exportToFilesystemDefinition(self):
""" """
Return the filesystem definition of this ZODB property Return the filesystem definition of this ZODB property
""" """
property_default_value = self._convertValueToTalesExpression(
self.getPropertyDefault())
return {'id': self.getReference(), return {'id': self.getReference(),
'description': self.getDescription(), 'description': self.getDescription(),
'type': self.getElementaryType(), 'type': self.getElementaryType(),
'storage_id': self.getStorageId(), 'storage_id': self.getStorageId(),
'multivalued': self.getMultivalued(), 'multivalued': self.getMultivalued(),
'default': self.getPropertyDefault(), 'default': property_default_value,
'range': self.getRange(), 'range': self.getRange(),
'preference': self.getPreference(), 'preference': self.getPreference(),
'read_permission': self.getReadPermission(), 'read_permission': self.getReadPermission(),
......
...@@ -255,6 +255,7 @@ class TestZodbPropertySheet(ERP5TypeTestCase): ...@@ -255,6 +255,7 @@ class TestZodbPropertySheet(ERP5TypeTestCase):
return self.test_property_sheet.newContent( return self.test_property_sheet.newContent(
portal_type='Standard Property', portal_type='Standard Property',
reference='test_standard_property_' + operation_type, reference='test_standard_property_' + operation_type,
property_default='python: "test_default_value"',
elementary_type='string') elementary_type='string')
def _newAcquiredProperty(self, operation_type): def _newAcquiredProperty(self, operation_type):
...@@ -478,6 +479,9 @@ class TestZodbPropertySheet(ERP5TypeTestCase): ...@@ -478,6 +479,9 @@ class TestZodbPropertySheet(ERP5TypeTestCase):
# Standard Property # Standard Property
self.assertHasAttribute(new_person, 'setTestStandardPropertyAssign') self.assertHasAttribute(new_person, 'setTestStandardPropertyAssign')
self.assertEquals(new_person.getTestStandardPropertyAssign(),
"test_default_value")
new_person.setTestStandardPropertyAssign('value') new_person.setTestStandardPropertyAssign('value')
self.assertEquals(new_person.getTestStandardPropertyAssign(), 'value') self.assertEquals(new_person.getTestStandardPropertyAssign(), 'value')
......
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