From c2db1d36527b9ff736ae5b9ed9731581776f335e Mon Sep 17 00:00:00 2001 From: Renaud Le Gac <renaud.legac@free.fr> Date: Mon, 22 Nov 2010 21:01:37 +0000 Subject: [PATCH] Deploy the tool customize_grid_with_template_column in the configuration service. --- modules/plugin_dbui/cfgsvc.py | 81 +++++++++++++++++++++++------------ 1 file changed, 54 insertions(+), 27 deletions(-) diff --git a/modules/plugin_dbui/cfgsvc.py b/modules/plugin_dbui/cfgsvc.py index 008b542d..e91518c1 100644 --- a/modules/plugin_dbui/cfgsvc.py +++ b/modules/plugin_dbui/cfgsvc.py @@ -42,41 +42,68 @@ class CfgSvc(object): setattr(self, '_%s' % key, pluginManager.dbui[key]) - def _getColumnsModel(self, tablename): - """ Generate columns model required by the gridPanel widget. - The method return a list. + def _getColumn(self, tablename, fieldname): + """ Return a dictionary with the column model + required by the gridPanel widget. """ - li = [] - - for fieldname in self._db[tablename].fields: - col = {} - field = self._db[tablename][fieldname] + col = {} + field = self._db[tablename][fieldname] - # column header - col["header"] = str(self._translate(field.label)) - - # replace foreign key by the pointing column - if self._is_foreign_field(tablename, fieldname): - - k_tablename, k_fieldname, k_key = \ - self._get_foreign_data(tablename, fieldname) - col["dataIndex"] = encode_field(k_tablename, k_fieldname) + # column header + col["header"] = str(self._translate(field.label)) + + # replace foreign key by the pointing column + if self._is_foreign_field(tablename, fieldname): - # standard column - else: - col["dataIndex"] = encode_field(tablename, fieldname) - - col["sortable"] = True + k_tablename, k_fieldname, k_key = \ + self._get_foreign_data(tablename, fieldname) + col["dataIndex"] = encode_field(k_tablename, k_fieldname) + + # standard column + else: + col["dataIndex"] = encode_field(tablename, fieldname) - # hide the primary key - # and field which are not readable and not writable - if fieldname == "id" or ((not field.readable) and (not field.writable)): + col["sortable"] = True + + # hide the primary key + # and field which are not readable and not writable + if fieldname == "id" or ((not field.readable) and (not field.writable)): + col["hidden"] = True + + # Hide fields request customizing the grid + if tablename in self._hidden_columns: + if fieldname in self._hidden_columns[tablename]: col["hidden"] = True + + return col - li.append(col) - + + def _getColumnsModel(self, tablename): + """ Return the columns model required by the gridPanel widget + handling customize columns. + + """ + + li= [] + + # standard column + for fieldname in self._db[tablename].fields: + li.append(self._getColumn(tablename, fieldname)) + + # template column + if tablename in self._template_columns: + for el in self._template_columnd[tablename]: + + data = self._template_columns[tablename] + col = {'xtype': 'templatecolumn', + 'header': data.header, + 'tpl': data.tpl, + 'sortable': True} + + li.insert(data.ipos, col) + return li -- GitLab