Commit cd1a5a22 authored by Arnaud Fontaine's avatar Arnaud Fontaine

Convert 'default' attribute to a TALES expression for web-based Property Sheets

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@38999 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 28b7baa4
...@@ -59,8 +59,10 @@ class AcquiredProperty(StandardProperty): ...@@ -59,8 +59,10 @@ class AcquiredProperty(StandardProperty):
**StandardProperty._name_mapping_filesystem_to_web_dict) **StandardProperty._name_mapping_filesystem_to_web_dict)
# Web-based name of attributes whose value is a TALES Expression # Web-based name of attributes whose value is a TALES Expression
_expression_attribute_tuple = ('acquisition_portal_type', # string
'content_portal_type') _expression_attribute_tuple = \
StandardProperty._expression_attribute_tuple + \
('acquisition_portal_type', 'content_portal_type')
@staticmethod @staticmethod
def _convertValueToTalesExpression(value): def _convertValueToTalesExpression(value):
...@@ -68,7 +70,10 @@ class AcquiredProperty(StandardProperty): ...@@ -68,7 +70,10 @@ class AcquiredProperty(StandardProperty):
Convert a string value to a TALES expression for attributes listed Convert a string value to a TALES expression for attributes listed
in '_expression_attribute_tuple' in '_expression_attribute_tuple'
""" """
return value is None and value or Expression(value) if value is None:
return None
return Expression(value)
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'exportToFilesystemDefinition') 'exportToFilesystemDefinition')
...@@ -92,22 +97,3 @@ class AcquiredProperty(StandardProperty): ...@@ -92,22 +97,3 @@ class AcquiredProperty(StandardProperty):
'translation_acquired_property_id': self.getContentTranslationAcquiredPropertyIdList() or None}) 'translation_acquired_property_id': self.getContentTranslationAcquiredPropertyIdList() or None})
return filesystem_property_dict return filesystem_property_dict
def _convertFromFilesytemPropertyDict(self, filesystem_property_dict):
"""
Convert a property dict coming from a Property Sheet on the
filesystem to a web-based property dict
"""
web_property_dict = StandardProperty._convertFromFilesytemPropertyDict(
self, filesystem_property_dict)
# Update the properties whose values are TALES Expression
for attribute in self._expression_attribute_tuple:
if attribute in web_property_dict:
value = isinstance(web_property_dict[attribute], Expression) and \
web_property_dict[attribute].text or \
'python: ' + repr(web_property_dict[attribute])
web_property_dict[attribute] = value
return web_property_dict
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
############################################################################## ##############################################################################
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.CMFCore.Expression import Expression
from Products.ERP5Type import Permissions, PropertySheet from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5Type.XMLObject import XMLObject from Products.ERP5Type.XMLObject import XMLObject
...@@ -53,6 +54,10 @@ class StandardProperty(XMLObject): ...@@ -53,6 +54,10 @@ class StandardProperty(XMLObject):
'type': 'elementary_type', 'type': 'elementary_type',
'default': 'property_default'} 'default': 'property_default'}
# Web-based name of attributes whose value is a TALES Expression
# string
_expression_attribute_tuple = ('property_default',)
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'exportToFilesystemDefinition') 'exportToFilesystemDefinition')
def exportToFilesystemDefinition(self): def exportToFilesystemDefinition(self):
...@@ -81,12 +86,24 @@ class StandardProperty(XMLObject): ...@@ -81,12 +86,24 @@ class StandardProperty(XMLObject):
web_property_dict = {} web_property_dict = {}
for fs_property_name, value in filesystem_property_dict.iteritems(): for fs_property_name, value in filesystem_property_dict.iteritems():
# Property Sheets on the filesystem defined attributes whose
# value is None, or an empty tuple or string, or either 0, thus
# skip them
if not value:
continue
# Convert filesystem property name to web-based if necessary # Convert filesystem property name to web-based if necessary
web_property_name = \ web_property_name = \
fs_property_name in self._name_mapping_filesystem_to_web_dict and \ fs_property_name in self._name_mapping_filesystem_to_web_dict and \
self._name_mapping_filesystem_to_web_dict[fs_property_name] or \ self._name_mapping_filesystem_to_web_dict[fs_property_name] or \
fs_property_name fs_property_name
# Convert existing TALES expression class or primitive type to a
# TALES expression string
if web_property_name in self._expression_attribute_tuple:
value = isinstance(value, Expression) and \
value.text or 'python: ' + repr(value)
web_property_dict[web_property_name] = value web_property_dict[web_property_name] = value
return web_property_dict return web_property_dict
......
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