Commit 8cea69d4 authored by Jérome Perrin's avatar Jérome Perrin

ERP5Form/Selection: fix python3 compatibility

parent 06283ea3
......@@ -134,9 +134,9 @@ class Selection(Acquisition.Implicit, Traversable, Persistent):
if uids is None: uids = []
if columns is None: columns = []
if checked_uids is None: checked_uids = []
if six.PY2 and isinstance(method_path, six.text_type):
# XXX Because method_path is an URI, it must be in ASCII.
# Shouldn't Zope automatically does this conversion? -yo
if type(method_path) is type(u'a'):
method_path = method_path.encode('ascii')
self.method_path = method_path
self.params = params
......@@ -171,9 +171,9 @@ class Selection(Acquisition.Implicit, Traversable, Persistent):
if kw is not None:
for k,v in six.iteritems(kw):
if k in ('domain', 'report', 'domain_path', 'report_path', 'domain_list', 'report_list') or v is not None:
if six.PY2 and k == 'method_path' and isinstance(v, six.text_type):
# XXX Because method_path is an URI, it must be in ASCII.
# Shouldn't Zope automatically does this conversion? -yo
if k == 'method_path' and isinstance(v, six.text_type):
v = v.encode('ascii')
if getattr(self, k, None) != v:
setattr(self, k, v)
......@@ -214,12 +214,12 @@ class Selection(Acquisition.Implicit, Traversable, Persistent):
kw.setdefault("ignore_unknown_columns", True)
# Always remove '-C'-named parameter.
kw.pop('-C', None)
if self.invert_mode is not 0:
if self.invert_mode:
kw['uid'] = self.uids
if method is None or isinstance(method, str):
method_path = method or self.method_path
method = context.unrestrictedTraverse(method_path)
if type(method) is type('a'):
if isinstance(method, str):
method = context.unrestrictedTraverse(self.method_path)
sort_on = getattr(self, 'sort_on', [])
if len(sort_on) == 0:
......@@ -339,7 +339,7 @@ class Selection(Acquisition.Implicit, Traversable, Persistent):
def getZoom(self):
try:
current_zoom=self.params['zoom']
if current_zoom != None:
if current_zoom is not None:
return current_zoom
else:
return 1
......
......@@ -457,7 +457,7 @@ class SelectionTool( BaseTool, SimpleItem ):
if int(uid) in selection_uid_dict: del selection_uid_dict[int(uid)]
except (ValueError, TypeError):
if uid in selection_uid_dict: del selection_uid_dict[uid]
self.setSelectionCheckedUidsFor(list_selection_name, selection_uid_dict.keys(), REQUEST=REQUEST)
self.setSelectionCheckedUidsFor(list_selection_name, ensure_list(selection_uid_dict.keys()), REQUEST=REQUEST)
if REQUEST is not None:
return self._redirectToOriginalForm(REQUEST=REQUEST, form_id=form_id,
query_string=query_string, no_reset=True)
......@@ -1403,7 +1403,7 @@ class SelectionTool( BaseTool, SimpleItem ):
viewSearchRelatedDocumentDialog1,... if necessary
"""
aq_base_name = getattr(aq_base(self), name, None)
if aq_base_name == None:
if aq_base_name is None:
DYNAMIC_METHOD_NAME = 'viewSearchRelatedDocumentDialog'
method_name_length = len(DYNAMIC_METHOD_NAME)
......@@ -1414,15 +1414,15 @@ class SelectionTool( BaseTool, SimpleItem ):
method_count_string = method_count_string_list[0]
# be sure that method name is correct
try:
method_count = string.atoi(method_count_string)
except TypeError:
method_count = int(method_count_string)
except (TypeError, ValueError):
return aq_base_name
else:
if len(method_count_string_list) > 1:
# be sure that method name is correct
try:
sub_index = string.atoi(method_count_string_list[1])
except TypeError:
sub_index = int(method_count_string_list[1])
except (TypeError, ValueError):
return aq_base_name
else:
sub_index = None
......@@ -1539,7 +1539,7 @@ class SelectionTool( BaseTool, SimpleItem ):
def _getSelectionNameListFromContainer(self):
user_id = self._getUserId()
return list(set(self._getContainer().getSelectionNameList(user_id) +
list(self.getTemporarySelectionDict().keys())))
ensure_list(self.getTemporarySelectionDict().keys())))
def isAnonymous(self):
return self._getUserId() == 'Anonymous User'
......@@ -1604,7 +1604,7 @@ class TransactionalCacheContainer(MemcachedContainer):
class PersistentMappingContainer(BaseContainer):
def getSelectionNameList(self, user_id):
try:
return self._container[user_id].keys()
return ensure_list(self._container[user_id].keys())
except KeyError:
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