Commit 7093c2a5 authored by Vincent Pelletier's avatar Vincent Pelletier

ERP5Form.Listbox: Modernise getSelectedColumnList

Avoid double-calls when one is enough.
Avoid unused locals.
Avoid repeating conditions.
Inline single-use expressions.
parent f0890d93
...@@ -1094,33 +1094,32 @@ class ListBoxRenderer: ...@@ -1094,33 +1094,32 @@ class ListBoxRenderer:
def getSelectedColumnList(self): def getSelectedColumnList(self):
"""Return the list of selected columns. """Return the list of selected columns.
""" """
column_list = []
default_listbox_display_style = self.getDefaultDisplayStyle()
listbox_display_style = self.getListboxDisplayStyle() listbox_display_style = self.getListboxDisplayStyle()
dynamic_column_list_override = (self.getDisplayedColumnIdList() != None) displayed_column_id_list = self.getDisplayedColumnIdList()
list_style_column_change_required = listbox_display_style not in ('', DEFAULT_LISTBOX_DISPLAY_STYLE,) if displayed_column_id_list is not None:
if dynamic_column_list_override:
# dynamically setting columns is supported # dynamically setting columns is supported
#Create a dict to make a easy search
available_column_dict = {x[0]: x for x in self.getAllColumnList()} available_column_dict = {x[0]: x for x in self.getAllColumnList()}
# We check columns are present column_list = []
for id in self.getDisplayedColumnIdList(): for id in displayed_column_id_list:
try: try:
column_list.append(available_column_dict[id]) column_list.append(available_column_dict[id])
except KeyError: except KeyError:
raise AttributeError, "Column %s is not avaible" % id raise AttributeError("Column %s is not avaible" % (id, ))
elif list_style_column_change_required and not dynamic_column_list_override: return column_list
elif listbox_display_style not in ('', DEFAULT_LISTBOX_DISPLAY_STYLE):
# no dynamically setting of columns happens , still we have different than default # no dynamically setting of columns happens , still we have different than default
# listbox list style so try to get columns from 'More columns' # listbox list style so try to get columns from 'More columns'
list_style_prefix = "%s_" %listbox_display_style list_style_prefix = "%s_" % listbox_display_style
for column in self.getStyleColumnList(): return [
if column[1].startswith(list_style_prefix): (x[0], x[1].replace(list_style_prefix, ''))
column_list.append((column[0],column[1].replace(list_style_prefix, '',))) for x in self.getStyleColumnList()
else: if x[1].startswith(list_style_prefix)
column_list = self.getSelectionTool().getSelectionColumns(self.getSelectionName(), ]
columns = self.getColumnList(), return self.getSelectionTool().getSelectionColumns(
REQUEST = self.request) self.getSelectionName(),
return column_list columns=self.getColumnList(),
REQUEST=self.request,
)
@lazyMethod @lazyMethod
def getColumnAliasList(self): def getColumnAliasList(self):
......
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