Commit 8be67a1f authored by Arnaud Fontaine's avatar Arnaud Fontaine

py3: Port ListBox to Python3.

parent 3931f2b4
......@@ -670,7 +670,10 @@ class ListBoxRenderer:
def getTitle(self):
"""Return the title. Make sure that it is in unicode.
"""
if six.PY2:
return unicode(self.field.get_value('title'), self.getEncoding())
else:
return self.field.get_value('title')
def getMaxLineNumber(self):
"""Return the maximum number of lines shown in a page.
......@@ -859,7 +862,10 @@ class ListBoxRenderer:
"""Return the columns. Make sure that the titles are in unicode.
"""
columns = self.field.get_value('columns')
if six.PY2:
return [(str(c[0]), unicode(c[1], self.getEncoding())) for c in columns]
else:
return columns
@lazyMethod
def getAllColumnList(self):
......@@ -868,9 +874,14 @@ class ListBoxRenderer:
"""
all_column_list = list(self.getColumnList())
all_column_id_set = {c[0] for c in all_column_list}
if six.PY2:
all_column_list.extend((str(c[0]), unicode(c[1], self.getEncoding()))
for c in self.field.get_value('all_columns')
if c[0] not in all_column_id_set)
else:
all_column_list.extend(c
for c in self.field.get_value('all_columns')
if c[0] not in all_column_id_set)
return all_column_list
@lazyMethod
......@@ -885,7 +896,10 @@ class ListBoxRenderer:
"""
stat_columns = self.field.get_value('stat_columns')
if stat_columns:
if six.PY2:
stat_column_list = [(str(c[0]), unicode(c[1], self.getEncoding())) for c in stat_columns]
else:
stat_column_list = stat_columns
else:
stat_column_list = [(c[0], c[0]) for c in self.getAllColumnList()]
return stat_column_list
......@@ -915,22 +929,31 @@ class ListBoxRenderer:
"""Return the domain root list. Make sure that the titles are in unicode.
"""
domain_root_list = self.field.get_value('domain_root_list')
if six.PY2:
return [(str(c[0]), unicode(c[1], self.getEncoding())) for c in domain_root_list]
else:
return domain_root_list
@lazyMethod
def getReportRootList(self):
"""Return the report root list. Make sure that the titles are in unicode.
"""
report_root_list = self.field.get_value('report_root_list')
if six.PY2:
return [(str(c[0]), unicode(c[1], self.getEncoding())) for c in report_root_list]
else:
return report_root_list
@lazyMethod
def getDisplayStyleList(self):
"""Return the list of avaible display style. Make sure that the
titles are in unicode"""
display_style_list = self.field.get_value('display_style_list')
if six.PY2:
return [(str(c[0]), unicode(c[1], self.getEncoding())) for c in \
display_style_list]
else:
return display_style_list
@lazyMethod
def getDefaultDisplayStyle(self):
......@@ -1604,8 +1627,8 @@ class ListBoxRenderer:
param = param_dict.get(alias, param_dict.get(sql, u''))
if isinstance(param, dict):
param = param.get('query', u'')
if isinstance(param, str):
param = unicode(param, self.getEncoding())
if isinstance(param, six.binary_type):
param = six.text_type(param, self.getEncoding())
# Obtain a search field, if any.
form = self.getForm()
......@@ -1687,8 +1710,12 @@ class ListBoxRenderer:
if editable_field is not None:
processed_value = editable_field.render_view(value=original_value)
if not isinstance(processed_value, unicode):
if not isinstance(processed_value, six.text_type):
if six.PY2:
processed_value = unicode(str(processed_value), self.getEncoding(), 'replace')
else:
processed_value = str(processed_value).encode(
self.getEncoding(), 'replace').decode()
value_list.append((original_value, processed_value))
......@@ -2281,8 +2308,12 @@ class ListBoxRendererLine:
# Process the value.
if processed_value is None:
processed_value = u''
elif not isinstance(processed_value, unicode):
elif not isinstance(processed_value, six.text_type):
if six.PY2:
processed_value = unicode(str(processed_value), renderer.getEncoding(), 'replace')
else:
processed_value = str(processed_value).encode(
renderer.getEncoding(), 'replace').decode()
value_list.append((original_value, processed_value))
......@@ -2396,8 +2427,8 @@ class ListBoxHTMLRendererLine(ListBoxRendererLine):
except AttributeError:
pass
if isinstance(url, str):
url = unicode(url, encoding)
if isinstance(url, six.binary_type):
url = six.text_type(url, encoding)
if editable_field is not None:
uid = self.getUid()
......@@ -2460,8 +2491,8 @@ class ListBoxHTMLRendererLine(ListBoxRendererLine):
editable=(not self.isSummary()) \
and listbox_defines_column_as_editable and editable,
)
if isinstance(cell_html, str):
cell_html = unicode(cell_html, encoding)
if isinstance(cell_html, six.binary_type):
cell_html = six.text_type(cell_html, encoding)
else:
cell_html = u''
......@@ -2662,7 +2693,7 @@ class ListBoxListRenderer(ListBoxRenderer):
listboxline.checkLine(uid in checked_uid_set)
for (original_value, processed_value), (sql, title) in zip(line.getValueList(), self.getSelectedColumnList()):
if isinstance(original_value, unicode):
if isinstance(original_value, six.text_type):
value = original_value.encode(self.getEncoding())
else:
value = original_value
......@@ -2680,7 +2711,7 @@ class ListBoxListRenderer(ListBoxRenderer):
stat_listboxline.markStatLine()
for (original_value, processed_value), (sql, title) in zip(self.getStatValueList(), self.getSelectedColumnList()):
if isinstance(original_value, unicode):
if isinstance(original_value, six.text_type):
value = original_value.encode(self.getEncoding())
else:
value = original_value
......
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