diff --git a/product/ERP5Form/SelectionTool.py b/product/ERP5Form/SelectionTool.py index b15a10d7c88ae6e9d22f32be287ebdfa9ffab78d..2145d91380fb6349851fdd78e19b68b687e43a68 100644 --- a/product/ERP5Form/SelectionTool.py +++ b/product/ERP5Form/SelectionTool.py @@ -36,8 +36,8 @@ from Products.CMFCore.utils import UniqueObject from Globals import InitializeClass, DTMLFile, PersistentMapping, get_request from ZTUtils import make_query from AccessControl import ClassSecurityInfo +from Products.ERP5Type.Tool.BaseTool import BaseTool from Products.ERP5Type import Permissions as ERP5Permissions -from Products.ERP5Type import allowMemcachedTool from Products.ERP5Form import _dtmldir from Selection import Selection, DomainSelection from ZPublisher.HTTPRequest import FileUpload @@ -59,7 +59,7 @@ import warnings class SelectionError( Exception ): pass -class SelectionTool( UniqueObject, SimpleItem ): +class SelectionTool( BaseTool, UniqueObject, SimpleItem ): """ The SelectionTool object is the place holder for all methods and algorithms related to persistent selections @@ -68,7 +68,7 @@ class SelectionTool( UniqueObject, SimpleItem ): id = 'portal_selections' meta_type = 'ERP5 Selections' - + portal_type = 'Selection Tool' security = ClassSecurityInfo() # @@ -79,6 +79,9 @@ class SelectionTool( UniqueObject, SimpleItem ): }, { 'label' : 'View Selections' , 'action' : 'manage_view_selections' + }, + { 'label' : 'Configure' + , 'action' : 'manage_configure' } )) security.declareProtected( ERP5Permissions.ManagePortal @@ -89,6 +92,36 @@ class SelectionTool( UniqueObject, SimpleItem ): , 'manage_view_selections' ) manage_view_selections = DTMLFile( 'SelectionTool_manageViewSelections', _dtmldir ) + security.declareProtected( ERP5Permissions.ManagePortal + , 'manage_configure' ) + manage_configure = DTMLFile( 'SelectionTool_configure', _dtmldir ) + + # storages of SelectionTool + storage_list = ('Persistent Mapping', 'Memcached Tool') + + security.declareProtected( ERP5Permissions.ManagePortal, 'setStorage') + def setStorage(self, value, RESPONSE=None): + """ + Set the storage of Selection Tool. + """ + if value in self.storage_list: + self.storage = value + else: + raise ValueError, 'Given storage type (%s) is now supported.' % (value,) + if RESPONSE is not None: + RESPONSE.redirect('%s/manage_configure' % (self.absolute_url())) + + def getStorage(self, default=None): + if default is None: + default = self.storage_list[0] + storage = getattr(self, 'storage', default) + if storage is not default and storage not in self.storage_list: + storage = storage_list[0] + return storage + + def isMemcachedUsed(self): + return self.getStorage() == 'Memcached Tool' + def _redirectToOriginalForm(self, REQUEST=None, form_id=None, dialog_id=None, query_string=None, no_reset=False, no_report_depth=False): @@ -125,8 +158,8 @@ class SelectionTool( UniqueObject, SimpleItem ): """ Returns the selection names of the current user. """ - if allowMemcachedTool(): - raise SelectionError, 'getSelectionNameList is not supported if you use memcached tool.' + if self.isMemcachedUsed(): + return [] user_id = self.portal_membership.getAuthenticatedMember().getUserName() if user_id is not None: prefix = '%s-' % user_id @@ -155,7 +188,7 @@ class SelectionTool( UniqueObject, SimpleItem ): """ value = getattr(self, '_v_selection_data', None) if value is None: - if allowMemcachedTool(): + if self.isMemcachedUsed(): value = self.getPortalObject().portal_memcached.getMemcachedDict(key_prefix='selection_tool') else: value = PersistentMapping() diff --git a/product/ERP5Form/dtml/SelectionTool_configure.dtml b/product/ERP5Form/dtml/SelectionTool_configure.dtml new file mode 100644 index 0000000000000000000000000000000000000000..59621e70b5a26df035972704a2fed1f4df54c4d0 --- /dev/null +++ b/product/ERP5Form/dtml/SelectionTool_configure.dtml @@ -0,0 +1,23 @@ +<dtml-var manage_page_header> +<dtml-var manage_tabs> + +<h3>Selection Tool configuration</h3> +<p> + Selection Tool supports Memcached Tool and Persistent Mapping for its storage. +</p> +<div> + Current setting: <dtml-var getStorage html_quote> +</div> + +<form action="setStorage" method="post"> + <select name="value"> + <dtml-in "storage_list"> + <dtml-let selected="_['sequence-item'] == getStorage() and ' selected' or ''"> + <option value="&dtml-sequence-item;"&dtml-selected;>&dtml-sequence-item;</option> + </dtml-let> + </dtml-in> + </select> + <input type="submit" value="Change"/> +</form> + +<dtml-var manage_page_footer> diff --git a/product/ERP5Form/dtml/SelectionTool_manageViewSelections.dtml b/product/ERP5Form/dtml/SelectionTool_manageViewSelections.dtml index c9058f7a2e297f332e40071586482704cca71420..bc3dd86e692955f367b822626b28f6a1d29b4a94 100644 --- a/product/ERP5Form/dtml/SelectionTool_manageViewSelections.dtml +++ b/product/ERP5Form/dtml/SelectionTool_manageViewSelections.dtml @@ -5,6 +5,11 @@ form_title='View Selections', help_product='ERP5Form', )"> +<dtml-if isMemcachedUsed> +<p class="form-help"> +Listing active selections is not supported if you use memcached tool. +</p> +<dtml-else> <p class="form-help"> This page show the active selections for the current user. It is only useful for debug purposes. @@ -25,4 +30,5 @@ This page show the active selections for the current user. </dtml-in> </table> +</dtml-if> <dtml-var manage_page_footer> diff --git a/product/ERP5Form/tests/testSelectionTool.py b/product/ERP5Form/tests/testSelectionTool.py index b413b97e4bd4a9cf9a0fc7367bed54c1c1623a82..7e52189c60785d6b68b94808b86beb14fcf924a5 100644 --- a/product/ERP5Form/tests/testSelectionTool.py +++ b/product/ERP5Form/tests/testSelectionTool.py @@ -40,7 +40,6 @@ from zLOG import LOG from Testing import ZopeTestCase from Products.ERP5Type.Utils import get_request from Products.ERP5Form.Selection import Selection -from Products.ERP5Type import allowMemcachedTool class TestSelectionTool(ERP5TypeTestCase): @@ -64,17 +63,17 @@ class TestSelectionTool(ERP5TypeTestCase): def testGetSelectionNameList(self, quiet=quiet, run=run_all_test): if not run: return - if allowMemcachedTool(): - from Products.ERP5Form.SelectionTool import SelectionError - self.assertRaises(SelectionError, - self.portal_selections.getSelectionNameList) - self.assertRaises(SelectionError, - self.portal_selections.getSelectionNames) - else: - self.assertEquals(['test_selection'], - self.portal_selections.getSelectionNames()) - self.assertEquals(['test_selection'], - self.portal_selections.getSelectionNameList()) + # use persistent mapping by default + self.assertEquals(['test_selection'], + self.portal_selections.getSelectionNameList()) + self.assertEquals(['test_selection'], + self.portal_selections.getSelectionNames()) + # use memcached tool + self.portal_selections.setStorage('Memcached Tool') + self.assertEquals([], + self.portal_selections.getSelectionNameList()) + self.assertEquals([], + self.portal_selections.getSelectionNames()) def testGetSelectionFor(self, quiet=quiet, run=run_all_test): if not run: return