Commit bdf80a3b authored by Nicolas Delaby's avatar Nicolas Delaby

Add new action to allow selection deletion for all users

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@18851 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 0681aa55
...@@ -99,6 +99,17 @@ class SelectionTool( BaseTool, UniqueObject, SimpleItem ): ...@@ -99,6 +99,17 @@ class SelectionTool( BaseTool, UniqueObject, SimpleItem ):
return REQUEST.RESPONSE.redirect('%s/%s' % return REQUEST.RESPONSE.redirect('%s/%s' %
(self.absolute_url(), 'manage_viewSelections')) (self.absolute_url(), 'manage_viewSelections'))
security.declareProtected( ERP5Permissions.ManagePortal
, 'manage_deleteGlobalSelection' )
def manage_deleteGlobalSelection(self, selection_name, REQUEST=None):
"""
Relete a specified selection
"""
self._deleteGlobalSelectionFromContainer(selection_name)
if REQUEST is not None:
return REQUEST.RESPONSE.redirect('%s/%s' %
(self.absolute_url(), 'manage_viewSelections'))
# storages of SelectionTool # storages of SelectionTool
storage_list = ('Persistent Mapping', 'Memcached Tool') storage_list = ('Persistent Mapping', 'Memcached Tool')
...@@ -1249,6 +1260,19 @@ class SelectionTool( BaseTool, UniqueObject, SimpleItem ): ...@@ -1249,6 +1260,19 @@ class SelectionTool( BaseTool, UniqueObject, SimpleItem ):
else: else:
del(self._getPersistentContainer(user_id)[selection_name]) del(self._getPersistentContainer(user_id)[selection_name])
def _deleteGlobalSelectionFromContainer(self, selection_name):
id_list = []
if self.isMemcachedUsed():
for k in self._getMemcachedContainer().keys():
if k.split('-')[1] == selection_name:
del(self._getMemcachedContainer()[k])
else:
if getattr(aq_base(self), 'selection_data', None) is not None:
for user_id in self.selection_data.keys():
mapping = self._getPersistentContainer(user_id)
if mapping.has_key(selection_name):
del(mapping[selection_name])
def _getSelectionNameListFromContainer(self): def _getSelectionNameListFromContainer(self):
if self.isMemcachedUsed(): if self.isMemcachedUsed():
return [] return []
...@@ -1258,14 +1282,14 @@ class SelectionTool( BaseTool, UniqueObject, SimpleItem ): ...@@ -1258,14 +1282,14 @@ class SelectionTool( BaseTool, UniqueObject, SimpleItem ):
return self._getPersistentContainer(user_id).keys() return self._getPersistentContainer(user_id).keys()
def _getMemcachedContainer(self): def _getMemcachedContainer(self):
value = getattr(self, '_v_selection_data', None) value = getattr(aq_base(self), '_v_selection_data', None)
if value is None: if value is None:
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) setattr(self, '_v_selection_data', value)
return value return value
def _getPersistentContainer(self, user_id): def _getPersistentContainer(self, user_id):
if getattr(self, 'selection_data', None) is None: if getattr(aq_base(self), 'selection_data', None) is None:
self.selection_data = PersistentMapping() self.selection_data = PersistentMapping()
if not self.selection_data.has_key(user_id): if not self.selection_data.has_key(user_id):
self.selection_data[user_id] = SelectionPersistentMapping() self.selection_data[user_id] = SelectionPersistentMapping()
......
...@@ -24,7 +24,8 @@ This page show the active selections for the current user. ...@@ -24,7 +24,8 @@ This page show the active selections for the current user.
<dtml-in getSelectionNameList> <dtml-in getSelectionNameList>
<tr> <tr>
<td><a href="manage_deleteSelection?selection_name=<dtml-var sequence-item>">Delete</a></td> <td><a href="manage_deleteSelection?selection_name=<dtml-var sequence-item>">Delete (user)</a></td>
<td><a href="manage_deleteGlobalSelection?selection_name=<dtml-var sequence-item>">Delete (Global)</a></td>
<td> <dtml-var sequence-item></td> <td> <dtml-var sequence-item></td>
<td> <dtml-var <td> <dtml-var
expr="getSelectionParams(_['sequence-item'])" html_quote></td> expr="getSelectionParams(_['sequence-item'])" html_quote></td>
......
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