Commit 4d5df6e7 authored by Vincent Pelletier's avatar Vincent Pelletier

Move selection checksum computation next to its verification.

Allows getting current selection's MD5 even outside ListBox's renderer.
parent fccc263c
...@@ -50,7 +50,6 @@ from Products.ERP5Type.Globals import InitializeClass, get_request ...@@ -50,7 +50,6 @@ from Products.ERP5Type.Globals import InitializeClass, get_request
from Products.PythonScripts.Utility import allow_class from Products.PythonScripts.Utility import allow_class
from Products.PageTemplates.PageTemplateFile import PageTemplateFile from Products.PageTemplates.PageTemplateFile import PageTemplateFile
from warnings import warn from warnings import warn
from hashlib import md5
import cgi import cgi
DEFAULT_LISTBOX_DISPLAY_STYLE = 'table' DEFAULT_LISTBOX_DISPLAY_STYLE = 'table'
...@@ -2560,20 +2559,14 @@ class ListBoxHTMLRenderer(ListBoxRenderer): ...@@ -2560,20 +2559,14 @@ class ListBoxHTMLRenderer(ListBoxRenderer):
"""Generate a MD5 checksum against checked uids. This is used to confirm """Generate a MD5 checksum against checked uids. This is used to confirm
that selected values do not change between a display of a dialog and an execution. that selected values do not change between a display of a dialog and an execution.
FIXME: this should only use getCheckedUidList, but Folder_deleteObjectList does not use FIXME: SelectionTool.getSelectionChecksum's uid_list parameter is
the feature that checked uids are used when no list method is specified. deprecated, but Folder_deleteObjectList does not use the feature that
checked uids are used when no list method is specified.
""" """
checked_uid_list = self.request.get('uids') return self.getSelectionTool().getSelectionChecksum(
if checked_uid_list is None: self.getSelectionName(),
checked_uid_list = self.getCheckedUidList() uid_list=self.request.get('uids'),
if checked_uid_list is not None: )
checked_uid_list = [str(uid) for uid in checked_uid_list]
checked_uid_list.sort()
md5_string = md5(str(checked_uid_list)).hexdigest()
else:
md5_string = None
return md5_string
def getPhysicalRoot(self): def getPhysicalRoot(self):
"""Return the physical root (an Application object). This method is required for """Return the physical root (an Application object). This method is required for
......
...@@ -1170,13 +1170,26 @@ class SelectionTool( BaseTool, SimpleItem ): ...@@ -1170,13 +1170,26 @@ class SelectionTool( BaseTool, SimpleItem ):
""" """
We want to be sure that the selection did not change We want to be sure that the selection did not change
""" """
return object_uid_list != self._getUIDListChecksum(object_uid_list)
security.declareProtected(ERP5Permissions.View, 'getSelectionChecksum')
def getSelectionChecksum(self, selection_name, uid_list=None):
"""Generate an MD5 checksum against checked uids. This is used to confirm
that selected values do not change between a display of a dialog and an execution.
uid_list (deprecated)
For backward compatibility with code not updating selected uids.
"""
if uid_list is None:
uid_list = self.getSelectionCheckedUidsFor(selection_name,
REQUEST=REQUEST)
return self._getUIDListChecksum(uid_list)
def _getUIDListChecksum(self, uid_list):
if uid_list is None:
return None
# XXX To avoid the difference of the string representations of int and long, # XXX To avoid the difference of the string representations of int and long,
# convert each element to a string. # convert each element to a string.
object_uid_list = [str(x) for x in object_uid_list] return md5(str(sorted(str(uid) for uid in uid_list))).hexdigest()
object_uid_list.sort()
new_md5_string = md5(str(object_uid_list)).hexdigest()
return md5_string != new_md5_string
# Related document searching # Related document searching
def viewSearchRelatedDocumentDialog(self, index, form_id, def viewSearchRelatedDocumentDialog(self, index, form_id,
......
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