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 @@ ...@@ -28,9 +28,11 @@
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.CMFCore.Expression import Expression 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 import Permissions, PropertySheet
from Products.ERP5Type.Core.CategoryProperty import CategoryProperty from Products.ERP5Type.Core.CategoryProperty import CategoryProperty
from Products.ERP5Type.Core.StandardProperty import StandardProperty
class DynamicCategoryProperty(CategoryProperty): class DynamicCategoryProperty(CategoryProperty):
""" """
...@@ -48,6 +50,7 @@ class DynamicCategoryProperty(CategoryProperty): ...@@ -48,6 +50,7 @@ class DynamicCategoryProperty(CategoryProperty):
property_sheets = (PropertySheet.SimpleItem, property_sheets = (PropertySheet.SimpleItem,
PropertySheet.DynamicCategoryProperty) PropertySheet.DynamicCategoryProperty)
# TODO: REMOVE
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'exportToFilesystemDefinition') 'exportToFilesystemDefinition')
def exportToFilesystemDefinition(self): def exportToFilesystemDefinition(self):
...@@ -73,15 +76,19 @@ class DynamicCategoryProperty(CategoryProperty): ...@@ -73,15 +76,19 @@ class DynamicCategoryProperty(CategoryProperty):
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'applyOnAccessorHolder') 'applyOnAccessorHolder')
def applyOnAccessorHolder(self, accessor_holder, expression_context, portal): def applyOnAccessorHolder(self, accessor_holder, expression_context, portal):
expression_string = self.getCategoryExpression() category_id_list = evaluateExpressionFromString(expression_context,
if expression_string is not None: self.getCategoryExpression())
expression = Expression(expression_string)
value = expression(expression_context) if not isinstance(category_id_list, (tuple, list)):
category_id_list = [category_id_list]
category_tool = getattr(portal, 'portal_categories', None) for category_id in category_id_list:
if not isinstance(value, (tuple, list)): try:
value = [value] self.applyDefinitionOnAccessorHolder(accessor_holder,
for category_id in value:
self.applyPropertyOnAccessorHolder(accessor_holder,
category_id, category_id,
category_tool) 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