From b4a58c0887ce5ebf13739cde63af9dce4c6a47c5 Mon Sep 17 00:00:00 2001
From: Renaud Le Gac <renaud.legac@free.fr>
Date: Sun, 6 Nov 2011 20:53:43 +0100
Subject: [PATCH] Add the method configure_column in GridModifier

---
 models/db_widgets.py                |  6 ++++++
 modules/plugin_dbui/cfgsvc.py       |  6 +++++-
 modules/plugin_dbui/gridmodifier.py | 12 ++++++++++++
 static/plugin_dbui/CHANGELOG        |  3 +++
 4 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/models/db_widgets.py b/models/db_widgets.py
index 6f797ef1..539eb1d6 100755
--- a/models/db_widgets.py
+++ b/models/db_widgets.py
@@ -123,6 +123,12 @@ formModifier.configure(buttonAlign='right',
                        height=380,
                        defaults={'height': 320})
 
+#
+# fine tune categories_aeres grid
+#
+gridModifier = dbui.GridModifier('categories_aeres')
+gridModifier.configure_column('code', width=10)
+
 #
 # Define a column template for the publications grid
 #
diff --git a/modules/plugin_dbui/cfgsvc.py b/modules/plugin_dbui/cfgsvc.py
index 686fea6b..791c3e3c 100755
--- a/modules/plugin_dbui/cfgsvc.py
+++ b/modules/plugin_dbui/cfgsvc.py
@@ -141,13 +141,17 @@ class CfgSvc(BaseSvc):
         
         grid_modifiers = self.environment['plugins'].dbui.grid_modifiers
         if tablename in grid_modifiers:
+            configure_columns = grid_modifiers[tablename].configure_columns
             delete_columns = grid_modifiers[tablename].delete_columns
             template_columns = grid_modifiers[tablename].template_columns
         
         # standard column
         for fieldname in db[tablename].fields:
             if fieldname not in delete_columns:
-                li.append(self._get_column(tablename, fieldname))
+                model = self._get_column(tablename, fieldname)
+                if fieldname in configure_columns:
+                    model.update(configure_columns[fieldname])
+                li.append(model)
         
         # template column
         for el in template_columns:
diff --git a/modules/plugin_dbui/gridmodifier.py b/modules/plugin_dbui/gridmodifier.py
index 59a5abd5..46dc7f1b 100644
--- a/modules/plugin_dbui/gridmodifier.py
+++ b/modules/plugin_dbui/gridmodifier.py
@@ -48,6 +48,7 @@ class GridModifier(Modifier):
         """
         Modifier.__init__(self, GRID_MODIFIERS, tablename)
         
+        self.data.configure_columns = {}
         self.data.delete_columns = []
         self.data.grid_filters = []
         self.data.hidden_columns = []
@@ -67,6 +68,17 @@ class GridModifier(Modifier):
         """
 
 
+    def configure_column(self, fieldname, **kwargs):
+        """Modified the model of a given column.
+        This method is useful to fine tune column width for example.
+
+        The keyword arguments defines the configuration option
+        of the underlying Ext.grid.Column
+
+        """
+        self.data.configure_columns[fieldname] = kwargs
+
+        
     def delete_columns(self, *fields):
         """Delete the columns in the Ext.grid.GridPanel widget.
         Each column is identified by its database field name.
diff --git a/static/plugin_dbui/CHANGELOG b/static/plugin_dbui/CHANGELOG
index e0835b0e..0cbefb00 100644
--- a/static/plugin_dbui/CHANGELOG
+++ b/static/plugin_dbui/CHANGELOG
@@ -1,5 +1,8 @@
 --------------------------------- CHANGE LOG ----------------------------------
 
+0.4.x (Rev)
+  - Improve the GridModifier to modify column parameters.
+  
 0.4.2 (Oct 11)
   - Migrate to git and to ExtJS 3.4
   - Backport the modifiers syntax developped in the branch 0.5.x
-- 
GitLab