Commit 7db7ff2b authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

* make a ZMI interface for configuring a storage for Selection Tool

* return [] instead of raising a exception in getSelectionNameList with memcached tool


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@13891 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent cd2f55c4
...@@ -36,8 +36,8 @@ from Products.CMFCore.utils import UniqueObject ...@@ -36,8 +36,8 @@ from Products.CMFCore.utils import UniqueObject
from Globals import InitializeClass, DTMLFile, PersistentMapping, get_request from Globals import InitializeClass, DTMLFile, PersistentMapping, get_request
from ZTUtils import make_query from ZTUtils import make_query
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.ERP5Type.Tool.BaseTool import BaseTool
from Products.ERP5Type import Permissions as ERP5Permissions from Products.ERP5Type import Permissions as ERP5Permissions
from Products.ERP5Type import allowMemcachedTool
from Products.ERP5Form import _dtmldir from Products.ERP5Form import _dtmldir
from Selection import Selection, DomainSelection from Selection import Selection, DomainSelection
from ZPublisher.HTTPRequest import FileUpload from ZPublisher.HTTPRequest import FileUpload
...@@ -59,7 +59,7 @@ import warnings ...@@ -59,7 +59,7 @@ import warnings
class SelectionError( Exception ): class SelectionError( Exception ):
pass pass
class SelectionTool( UniqueObject, SimpleItem ): class SelectionTool( BaseTool, UniqueObject, SimpleItem ):
""" """
The SelectionTool object is the place holder for all The SelectionTool object is the place holder for all
methods and algorithms related to persistent selections methods and algorithms related to persistent selections
...@@ -68,7 +68,7 @@ class SelectionTool( UniqueObject, SimpleItem ): ...@@ -68,7 +68,7 @@ class SelectionTool( UniqueObject, SimpleItem ):
id = 'portal_selections' id = 'portal_selections'
meta_type = 'ERP5 Selections' meta_type = 'ERP5 Selections'
portal_type = 'Selection Tool'
security = ClassSecurityInfo() security = ClassSecurityInfo()
# #
...@@ -79,6 +79,9 @@ class SelectionTool( UniqueObject, SimpleItem ): ...@@ -79,6 +79,9 @@ class SelectionTool( UniqueObject, SimpleItem ):
}, },
{ 'label' : 'View Selections' { 'label' : 'View Selections'
, 'action' : 'manage_view_selections' , 'action' : 'manage_view_selections'
},
{ 'label' : 'Configure'
, 'action' : 'manage_configure'
} )) } ))
security.declareProtected( ERP5Permissions.ManagePortal security.declareProtected( ERP5Permissions.ManagePortal
...@@ -89,6 +92,36 @@ class SelectionTool( UniqueObject, SimpleItem ): ...@@ -89,6 +92,36 @@ class SelectionTool( UniqueObject, SimpleItem ):
, 'manage_view_selections' ) , 'manage_view_selections' )
manage_view_selections = DTMLFile( 'SelectionTool_manageViewSelections', _dtmldir ) 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, def _redirectToOriginalForm(self, REQUEST=None, form_id=None, dialog_id=None,
query_string=None, query_string=None,
no_reset=False, no_report_depth=False): no_reset=False, no_report_depth=False):
...@@ -125,8 +158,8 @@ class SelectionTool( UniqueObject, SimpleItem ): ...@@ -125,8 +158,8 @@ class SelectionTool( UniqueObject, SimpleItem ):
""" """
Returns the selection names of the current user. Returns the selection names of the current user.
""" """
if allowMemcachedTool(): if self.isMemcachedUsed():
raise SelectionError, 'getSelectionNameList is not supported if you use memcached tool.' return []
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:
prefix = '%s-' % user_id prefix = '%s-' % user_id
...@@ -155,7 +188,7 @@ class SelectionTool( UniqueObject, SimpleItem ): ...@@ -155,7 +188,7 @@ class SelectionTool( UniqueObject, SimpleItem ):
""" """
value = getattr(self, '_v_selection_data', None) value = getattr(self, '_v_selection_data', None)
if value is None: if value is None:
if allowMemcachedTool(): if self.isMemcachedUsed():
value = self.getPortalObject().portal_memcached.getMemcachedDict(key_prefix='selection_tool') value = self.getPortalObject().portal_memcached.getMemcachedDict(key_prefix='selection_tool')
else: else:
value = PersistentMapping() value = PersistentMapping()
......
<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>
...@@ -5,6 +5,11 @@ ...@@ -5,6 +5,11 @@
form_title='View Selections', form_title='View Selections',
help_product='ERP5Form', 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"> <p class="form-help">
This page show the active selections for the current user. This page show the active selections for the current user.
It is only useful for debug purposes. It is only useful for debug purposes.
...@@ -25,4 +30,5 @@ This page show the active selections for the current user. ...@@ -25,4 +30,5 @@ This page show the active selections for the current user.
</dtml-in> </dtml-in>
</table> </table>
</dtml-if>
<dtml-var manage_page_footer> <dtml-var manage_page_footer>
...@@ -40,7 +40,6 @@ from zLOG import LOG ...@@ -40,7 +40,6 @@ from zLOG import LOG
from Testing import ZopeTestCase from Testing import ZopeTestCase
from Products.ERP5Type.Utils import get_request from Products.ERP5Type.Utils import get_request
from Products.ERP5Form.Selection import Selection from Products.ERP5Form.Selection import Selection
from Products.ERP5Type import allowMemcachedTool
class TestSelectionTool(ERP5TypeTestCase): class TestSelectionTool(ERP5TypeTestCase):
...@@ -64,17 +63,17 @@ class TestSelectionTool(ERP5TypeTestCase): ...@@ -64,17 +63,17 @@ class TestSelectionTool(ERP5TypeTestCase):
def testGetSelectionNameList(self, quiet=quiet, run=run_all_test): def testGetSelectionNameList(self, quiet=quiet, run=run_all_test):
if not run: return if not run: return
if allowMemcachedTool(): # use persistent mapping by default
from Products.ERP5Form.SelectionTool import SelectionError self.assertEquals(['test_selection'],
self.assertRaises(SelectionError, self.portal_selections.getSelectionNameList())
self.portal_selections.getSelectionNameList) self.assertEquals(['test_selection'],
self.assertRaises(SelectionError, self.portal_selections.getSelectionNames())
self.portal_selections.getSelectionNames) # use memcached tool
else: self.portal_selections.setStorage('Memcached Tool')
self.assertEquals(['test_selection'], self.assertEquals([],
self.portal_selections.getSelectionNames()) self.portal_selections.getSelectionNameList())
self.assertEquals(['test_selection'], self.assertEquals([],
self.portal_selections.getSelectionNameList()) self.portal_selections.getSelectionNames())
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