Commit a5015ace authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

* rename getSelectionNames to getSelectionNameList.

* support both memcached and persistentmapping as the storage of
  selection tools.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@13809 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 00261a15
...@@ -41,6 +41,8 @@ from Products.ERP5.Document.Domain import Domain ...@@ -41,6 +41,8 @@ from Products.ERP5.Document.Domain import Domain
from zLOG import LOG from zLOG import LOG
from Products.ERP5Type.Tool.MemcachedTool import MEMCACHED_TOOL_MODIFIED_FLAG_PROPERTY_ID
class Selection(Acquisition.Implicit, Traversable, Persistent): class Selection(Acquisition.Implicit, Traversable, Persistent):
""" """
Selection Selection
...@@ -156,6 +158,7 @@ class Selection(Acquisition.Implicit, Traversable, Persistent): ...@@ -156,6 +158,7 @@ class Selection(Acquisition.Implicit, Traversable, Persistent):
security.declarePrivate('edit') security.declarePrivate('edit')
def edit(self, params=None, **kw): def edit(self, params=None, **kw):
setattr(self, MEMCACHED_TOOL_MODIFIED_FLAG_PROPERTY_ID, True)
if params is not None: if params is not None:
self.params = {} self.params = {}
for key in params.keys(): for key in params.keys():
......
############################################################################## ##############################################################################
# #
# Copyright (c) 2002 Nexedi SARL and Contributors. All Rights Reserved. # Copyright (c) 2002,2007 Nexedi SARL and Contributors. All Rights Reserved.
# Jean-Paul Smets-Solanes <jp@nexedi.com> # Jean-Paul Smets-Solanes <jp@nexedi.com>
# #
# WARNING: This program as such is intended to be used by professional # WARNING: This program as such is intended to be used by professional
...@@ -37,6 +37,7 @@ from Globals import InitializeClass, DTMLFile, PersistentMapping, get_request ...@@ -37,6 +37,7 @@ 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 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
...@@ -118,21 +119,17 @@ class SelectionTool( UniqueObject, SimpleItem ): ...@@ -118,21 +119,17 @@ class SelectionTool( UniqueObject, SimpleItem ):
form_id = dialog_id or REQUEST.get('dialog_id', None) or form_id or REQUEST.get('form_id', 'view') form_id = dialog_id or REQUEST.get('dialog_id', None) or form_id or REQUEST.get('form_id', 'view')
return getattr(context, form_id)() return getattr(context, form_id)()
security.declareProtected(ERP5Permissions.View, 'getSelectionNames') security.declareProtected(ERP5Permissions.View, 'getSelectionNameList')
def getSelectionNames(self, context=None, REQUEST=None): def getSelectionNameList(self, context=None, REQUEST=None):
""" """
Returns the selection names of the current user. Returns the selection names of the current user.
NOTE - The naming getSelectionNames is wrong. It
should be getSelectionNameList to follow conventions
""" """
if context is None: context = self if allowMemcachedTool():
if not REQUEST: raise SelectionError, 'getSelectionNameList is not supported if you use memcached tool.'
REQUEST = get_request() user_id = self.portal_membership.getAuthenticatedMember().getUserName()
if hasattr(self, 'selection_data'): if user_id is not None:
user_id = self.portal_membership.getAuthenticatedMember().getUserName() prefix = '%s-' % user_id
if user_id is not None and self.selection_data.has_key(user_id): return [x.replace(prefix, '', 1) for x in self.getSelectionContainer().keys() if x.startswith(prefix)]
return self.selection_data[user_id].keys()
return [] return []
security.declareProtected(ERP5Permissions.View, 'callSelectionFor') security.declareProtected(ERP5Permissions.View, 'callSelectionFor')
...@@ -143,23 +140,30 @@ class SelectionTool( UniqueObject, SimpleItem ): ...@@ -143,23 +140,30 @@ class SelectionTool( UniqueObject, SimpleItem ):
return None return None
return selection(context=context) return selection(context=context)
def getSelectionContainer(self):
"""
Return the selection container.
"""
value = getattr(self, '_v_selection_data', None)
if value is None:
if allowMemcachedTool():
value = self.getPortalObject().portal_memcached.getMemcachedDict(key_prefix='selection_tool')
else:
value = PersistentMapping()
value.set = value.__setitem__
setattr(self, '_v_selection_data', value)
return value
security.declareProtected(ERP5Permissions.View, 'getSelectionFor') security.declareProtected(ERP5Permissions.View, 'getSelectionFor')
def getSelectionFor(self, selection_name, REQUEST=None): def getSelectionFor(self, selection_name, REQUEST=None):
""" """
Returns the selection instance for a given selection_name Returns the selection instance for a given selection_name
""" """
if REQUEST is None:
REQUEST = get_request()
if not hasattr(self, 'selection_data'):
self.selection_data = PersistentMapping()
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:
if not self.selection_data.has_key(user_id):
self.selection_data[user_id] = PersistentMapping()
if isinstance(selection_name, (tuple, list)): if isinstance(selection_name, (tuple, list)):
selection_name = selection_name[0] selection_name = selection_name[0]
selection = self.selection_data[user_id].get(selection_name, None) selection = self.getSelectionContainer().get('%s-%s' % (user_id, selection_name))
if selection is not None: if selection is not None:
return selection.__of__(self) return selection.__of__(self)
...@@ -172,42 +176,10 @@ class SelectionTool( UniqueObject, SimpleItem ): ...@@ -172,42 +176,10 @@ class SelectionTool( UniqueObject, SimpleItem ):
# Set the name so that this selection itself can get its own name. # Set the name so that this selection itself can get its own name.
selection_object.edit(name = selection_name) selection_object.edit(name = selection_name)
if not REQUEST: user_id = self.portal_membership.getAuthenticatedMember().getUserName()
REQUEST = get_request() if user_id is not None:
# New system: store directly - bypass session self.getSelectionContainer().set('%s-%s' % (user_id, selection_name), aq_base(selection_object))
if 0: return
user_id = self.portal_membership.getAuthenticatedMember().getUserName()
if user_id is not None:
self.selection_data.set((user_id, selection_name), selection_object)
return
# Another method: local dict
if 0:
if not hasattr(self, 'selection_data'):
self.selection_data = PersistentMapping()
user_id = self.portal_membership.getAuthenticatedMember().getUserName()
if user_id is not None:
self.selection_data[(user_id, selection_name)] = selection_object
return
# Another method: local dict but 2 stage to prevent user conflict
if 1:
if not hasattr(self, 'selection_data'):
self.selection_data = PersistentMapping()
user_id = self.portal_membership.getAuthenticatedMember().getUserName()
if user_id is not None:
if not self.selection_data.has_key(user_id):
self.selection_data[user_id] = PersistentMapping()
self.selection_data[user_id][selection_name] = aq_base(selection_object)
return
#try: CAUSES PROBLEMS WHY ??
if 1:
session = REQUEST.SESSION
selection_name = selection_name + '_selection_object'
session[selection_name] = selection_object
#except:
# LOG('WARNING ERP5Form SelectionTool',0,'Could not set Selection')
security.declareProtected(ERP5Permissions.View, 'getSelectionParamsFor') security.declareProtected(ERP5Permissions.View, 'getSelectionParamsFor')
def getSelectionParamsFor(self, selection_name, params=None, REQUEST=None): def getSelectionParamsFor(self, selection_name, params=None, REQUEST=None):
...@@ -352,7 +324,7 @@ class SelectionTool( UniqueObject, SimpleItem ): ...@@ -352,7 +324,7 @@ class SelectionTool( UniqueObject, SimpleItem ):
return selection.getListUrl() return selection.getListUrl()
else: else:
return None return None
security.declareProtected(ERP5Permissions.View, 'getSelectionInvertModeFor') security.declareProtected(ERP5Permissions.View, 'getSelectionInvertModeFor')
def getSelectionInvertModeFor(self, selection_name, REQUEST=None): def getSelectionInvertModeFor(self, selection_name, REQUEST=None):
"""Get the 'invert_mode' parameter of a selection. """Get the 'invert_mode' parameter of a selection.
...@@ -746,7 +718,7 @@ class SelectionTool( UniqueObject, SimpleItem ): ...@@ -746,7 +718,7 @@ class SelectionTool( UniqueObject, SimpleItem ):
if REQUEST is not None: if REQUEST is not None:
return self._redirectToOriginalForm(REQUEST=REQUEST, form_id=form_id, return self._redirectToOriginalForm(REQUEST=REQUEST, form_id=form_id,
query_string=query_string) query_string=query_string)
security.declareProtected(ERP5Permissions.View, 'setDomainRootFromParam') security.declareProtected(ERP5Permissions.View, 'setDomainRootFromParam')
def setDomainRootFromParam(self, REQUEST, selection_name, domain_root): def setDomainRootFromParam(self, REQUEST, selection_name, domain_root):
if REQUEST is None: if REQUEST is None:
...@@ -1224,7 +1196,7 @@ class SelectionTool( UniqueObject, SimpleItem ): ...@@ -1224,7 +1196,7 @@ class SelectionTool( UniqueObject, SimpleItem ):
security.declarePublic('buildSQLExpressionFromDomainSelection') security.declarePublic('buildSQLExpressionFromDomainSelection')
def buildSQLExpressionFromDomainSelection(self, selection_domain, def buildSQLExpressionFromDomainSelection(self, selection_domain,
table_map=None, domain_id=None, table_map=None, domain_id=None,
exclude_domain_id=None, exclude_domain_id=None,
strict_membership=0, strict_membership=0,
join_table="catalog", join_table="catalog",
...@@ -1324,8 +1296,8 @@ class TreeListLine: ...@@ -1324,8 +1296,8 @@ class TreeListLine:
return self.exception_uid_list return self.exception_uid_list
def makeTreeList(here, form, root_dict, report_path, base_category, def makeTreeList(here, form, root_dict, report_path, base_category,
depth, unfolded_list, form_id, selection_name, depth, unfolded_list, form_id, selection_name,
report_depth, is_report_opened=1, list_method=None, report_depth, is_report_opened=1, list_method=None,
filtered_portal_types=[] ,sort_on = (('id', 'ASC'),)): filtered_portal_types=[] ,sort_on = (('id', 'ASC'),)):
""" """
...@@ -1375,7 +1347,7 @@ def makeTreeList(here, form, root_dict, report_path, base_category, ...@@ -1375,7 +1347,7 @@ def makeTreeList(here, form, root_dict, report_path, base_category,
tree_list = [] tree_list = []
if root is None: return tree_list if root is None: return tree_list
if base_category == 'parent': if base_category == 'parent':
# Use searchFolder as default # Use searchFolder as default
if list_method is None: if list_method is None:
...@@ -1400,14 +1372,14 @@ def makeTreeList(here, form, root_dict, report_path, base_category, ...@@ -1400,14 +1372,14 @@ def makeTreeList(here, form, root_dict, report_path, base_category,
if sub_o is not None and hasattr(aq_base(root), 'objectValues'): if sub_o is not None and hasattr(aq_base(root), 'objectValues'):
exception_uid_list.append(sub_o.getUid()) exception_uid_list.append(sub_o.getUid())
# Summary (open) # Summary (open)
tree_list += [TreeListLine(o, 1, depth, 1, selection_domain, exception_uid_list)] tree_list += [TreeListLine(o, 1, depth, 1, selection_domain, exception_uid_list)]
if is_report_opened : if is_report_opened :
# List (contents, closed, must be strict selection) # List (contents, closed, must be strict selection)
tree_list += [TreeListLine(o, 0, depth, 0, selection_domain, exception_uid_list)] tree_list += [TreeListLine(o, 0, depth, 0, selection_domain, exception_uid_list)]
tree_list += makeTreeList(here, form, new_root_dict, report_path, tree_list += makeTreeList(here, form, new_root_dict, report_path,
base_category, depth + 1, unfolded_list, form_id, base_category, depth + 1, unfolded_list, form_id,
selection_name, report_depth, selection_name, report_depth,
is_report_opened=is_report_opened, sort_on=sort_on) is_report_opened=is_report_opened, sort_on=sort_on)
else: else:
tree_list += [TreeListLine(o, 1, depth, 0, selection_domain, ())] # Summary (closed) tree_list += [TreeListLine(o, 1, depth, 0, selection_domain, ())] # Summary (closed)
......
...@@ -16,7 +16,7 @@ This page show the active selections for the current user. ...@@ -16,7 +16,7 @@ This page show the active selections for the current user.
<th> Selection Parameters </th> <th> Selection Parameters </th>
</tr> </tr>
<dtml-in getSelectionNames> <dtml-in getSelectionNameList>
<tr> <tr>
<td> <dtml-var sequence-item></td> <td> <dtml-var sequence-item></td>
<td> <dtml-var <td> <dtml-var
......
...@@ -40,6 +40,7 @@ from zLOG import LOG ...@@ -40,6 +40,7 @@ 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):
...@@ -50,9 +51,7 @@ class TestSelectionTool(ERP5TypeTestCase): ...@@ -50,9 +51,7 @@ class TestSelectionTool(ERP5TypeTestCase):
return "SelectionTool" return "SelectionTool"
def getBusinessTemplateList(self): def getBusinessTemplateList(self):
# Use the same framework as the functional testing for convenience. return tuple()
# This adds some specific portal types and skins.
return ('erp5_ui_test',)
def afterSetUp(self): def afterSetUp(self):
uf = self.getPortal().acl_users uf = self.getPortal().acl_users
...@@ -63,10 +62,15 @@ class TestSelectionTool(ERP5TypeTestCase): ...@@ -63,10 +62,15 @@ 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 testGetSelectionNames(self, quiet=quiet, run=run_all_test): def testGetSelectionNameList(self, quiet=quiet, run=run_all_test):
if not run: return if not run: return
self.assertEquals(['test_selection'], if allowMemcachedTool():
self.portal_selections.getSelectionNames()) from Products.ERP5Form.SelectionTool import SelectionError
self.assertRaises(SelectionError,
self.portal_selections.getSelectionNameList)
else:
self.assertEquals(['test_selection'],
self.portal_selections.getSelectionNameList())
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