Commit 9b568d75 authored by Nicolas Dumazet's avatar Nicolas Dumazet

add tales expression to a predicate so that one can define simple conditions

without having to create dozens of unique Python scripts.



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@41813 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 17632c8a
......@@ -61,6 +61,13 @@ class Predicate:
'type' : 'lines',
'default' : (),
'mode' : 'w' },
{ 'id' : 'test_tales_expression',
'description' : 'A Tales expression to implement a simple ' \
'condition in Python. Runtime context of this ' \
'expression will be the tested document',
'type' : 'string',
'default' : 'python: True',
'mode' : 'w' },
{ 'id' : 'test_method_id',
'description' : 'A python method to implement additional tests',
'type' : 'lines', # Only a list of method ids is feasable for lines
......
......@@ -44,6 +44,7 @@ from Products.ERP5Type.Cache import getReadOnlyTransactionCache, enableReadOnlyT
from Products.ZSQLCatalog.SQLCatalog import SQLQuery
from Products.ERP5Type.Globals import PersistentMapping
from Products.ERP5Type.UnrestrictedMethod import UnrestrictedMethod
from Products.CMFCore.Expression import Expression
class Predicate(XMLObject):
"""
......@@ -207,6 +208,12 @@ class Predicate(XMLObject):
# '%s after method %s ' % (result, test_method_id))
if not result:
return result
test_tales_expression = self.getTestTalesExpression()
if test_tales_expression not in (None, '', 'python: True'):
expression = Expression(test_tales_expression)
from Products.ERP5Type.Utils import createExpressionContext
# evaluate a tales expression with the tested value as context
result = expression(createExpressionContext(context))
return result
@UnrestrictedMethod
......
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