Commit ffd19add authored by Arnaud Fontaine's avatar Arnaud Fontaine

For per-document accessors generation, rely on evaluateExpressionFromString

and skip invalid category after displaying a message in the logs


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@43884 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 9dbedf74
......@@ -28,9 +28,11 @@
from AccessControl import ClassSecurityInfo
from Products.CMFCore.Expression import Expression
from zLOG import LOG, INFO
from Products.ERP5Type.Utils import evaluateExpressionFromString
from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5Type.Core.CategoryProperty import CategoryProperty
from Products.ERP5Type.Core.StandardProperty import StandardProperty
class DynamicCategoryProperty(CategoryProperty):
"""
......@@ -48,6 +50,7 @@ class DynamicCategoryProperty(CategoryProperty):
property_sheets = (PropertySheet.SimpleItem,
PropertySheet.DynamicCategoryProperty)
# TODO: REMOVE
security.declareProtected(Permissions.AccessContentsInformation,
'exportToFilesystemDefinition')
def exportToFilesystemDefinition(self):
......@@ -73,15 +76,19 @@ class DynamicCategoryProperty(CategoryProperty):
security.declareProtected(Permissions.AccessContentsInformation,
'applyOnAccessorHolder')
def applyOnAccessorHolder(self, accessor_holder, expression_context, portal):
expression_string = self.getCategoryExpression()
if expression_string is not None:
expression = Expression(expression_string)
value = expression(expression_context)
category_id_list = evaluateExpressionFromString(expression_context,
self.getCategoryExpression())
if not isinstance(category_id_list, (tuple, list)):
category_id_list = [category_id_list]
category_tool = getattr(portal, 'portal_categories', None)
if not isinstance(value, (tuple, list)):
value = [value]
for category_id in value:
self.applyPropertyOnAccessorHolder(accessor_holder,
category_id,
category_tool)
for category_id in category_id_list:
try:
self.applyDefinitionOnAccessorHolder(accessor_holder,
category_id,
portal)
except ValueError, e:
# If one of the category defined is invalid, don't give up as
# the other ones may be fine
LOG("ERP5Type.Core.DynamicCategoryProperty", INFO,
"Invalid category: %s" % str(e))
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