Commit 5cfa3b01 authored by Jérome Perrin's avatar Jérome Perrin

add a dict like interface for selection tool, so that we can use this kind of

TALES expressions:
context/portal_selections/test_selection/not_found | string:default


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@17543 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 1311b0d1
......@@ -191,6 +191,9 @@ class SelectionTool( BaseTool, UniqueObject, SimpleItem ):
if selection is not None:
return selection.__of__(self)
def __getitem__(self, key):
return self.getSelectionParamsFor(key)
security.declareProtected(ERP5Permissions.View, 'setSelectionFor')
def setSelectionFor(self, selection_name, selection_object, REQUEST=None):
"""
......
......@@ -84,6 +84,18 @@ class TestSelectionTool(ERP5TypeTestCase):
self.assertEquals({'key':'value'},
self.portal_selections.getSelectionParamsFor('test_selection'))
def testGetSelectionParamsDictInterface(self):
self.assertEquals('value',
self.portal_selections['test_selection']['key'])
# the main use case is to have a dict interface in TALES expressions:
from Products.PageTemplates.Expressions import getEngine
evaluate_tales = getEngine().getContext(dict(context=self.portal)).evaluate
self.assertEquals('value',
evaluate_tales('context/portal_selections/test_selection/key'))
self.assertEquals('default', evaluate_tales(
'context/portal_selections/test_selection/not_found | string:default'))
def testCallSelectionFor(self, quiet=quiet, run=run_all_test):
if not run: return
self.assertEquals(None,
......
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