Commit df403d61 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

* use a non-volatile attribute name for selection container in using...

* use a non-volatile attribute name for selection container in using persistent mapping (closes #638).


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@13904 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 2765ddba
...@@ -186,14 +186,16 @@ class SelectionTool( BaseTool, UniqueObject, SimpleItem ): ...@@ -186,14 +186,16 @@ class SelectionTool( BaseTool, UniqueObject, SimpleItem ):
""" """
Return the selection container. Return the selection container.
""" """
if self.isMemcachedUsed():
value = getattr(self, '_v_selection_data', None) value = getattr(self, '_v_selection_data', None)
if value is None: if value is None:
if self.isMemcachedUsed():
value = self.getPortalObject().portal_memcached.getMemcachedDict(key_prefix='selection_tool') value = self.getPortalObject().portal_memcached.getMemcachedDict(key_prefix='selection_tool')
setattr(self, '_v_selection_data', value)
else: else:
value = getattr(self, '_selection_data', None)
if value is None:
value = PersistentMapping() value = PersistentMapping()
value.set = value.__setitem__ setattr(self, '_selection_data', value)
setattr(self, '_v_selection_data', value)
return value return value
security.declareProtected(ERP5Permissions.View, 'getSelectionFor') security.declareProtected(ERP5Permissions.View, 'getSelectionFor')
...@@ -220,7 +222,7 @@ class SelectionTool( BaseTool, UniqueObject, SimpleItem ): ...@@ -220,7 +222,7 @@ class SelectionTool( BaseTool, UniqueObject, SimpleItem ):
user_id = self.portal_membership.getAuthenticatedMember().getUserName() user_id = self.portal_membership.getAuthenticatedMember().getUserName()
if user_id is not None: if user_id is not None:
self.getSelectionContainer().set('%s-%s' % (user_id, selection_name), aq_base(selection_object)) self.getSelectionContainer()['%s-%s' % (user_id, selection_name)] = aq_base(selection_object)
return return
security.declareProtected(ERP5Permissions.View, 'getSelectionParamsFor') security.declareProtected(ERP5Permissions.View, 'getSelectionParamsFor')
......
...@@ -61,19 +61,25 @@ class TestSelectionTool(ERP5TypeTestCase): ...@@ -61,19 +61,25 @@ class TestSelectionTool(ERP5TypeTestCase):
self.portal_selections.setSelectionFor('test_selection', Selection()) self.portal_selections.setSelectionFor('test_selection', Selection())
self.portal_selections.setSelectionParamsFor('test_selection', {'key':'value'}) self.portal_selections.setSelectionParamsFor('test_selection', {'key':'value'})
def testGetSelectionNameList(self, quiet=quiet, run=run_all_test): def testGetSelectionContainer(self, quiet=quiet, run=run_all_test):
if not run: return if not run: return
# use persistent mapping by default # use persistent mapping by default
self.assertEquals(['test_selection'], self.assertEquals(['test_selection'],
self.portal_selections.getSelectionNameList()) self.portal_selections.getSelectionNameList())
self.assertEquals(['test_selection'], self.assertEquals(['test_selection'],
self.portal_selections.getSelectionNames()) self.portal_selections.getSelectionNames())
self.assert_(self.portal_selections.getSelectionContainer() is not None)
self.assert_(getattr(self.portal_selections, '_selection_data', None)
is not None)
# use memcached tool # use memcached tool
self.portal_selections.setStorage('Memcached Tool') self.portal_selections.setStorage('Memcached Tool')
self.assertEquals([], self.assertEquals([],
self.portal_selections.getSelectionNameList()) self.portal_selections.getSelectionNameList())
self.assertEquals([], self.assertEquals([],
self.portal_selections.getSelectionNames()) self.portal_selections.getSelectionNames())
self.assert_(self.portal_selections.getSelectionContainer() is not None)
self.assert_(getattr(self.portal_selections, '_v_selection_data', None)
is not None)
def testGetSelectionFor(self, quiet=quiet, run=run_all_test): def testGetSelectionFor(self, quiet=quiet, run=run_all_test):
if not run: return if not run: return
......
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