From e178e488ce990101a0a88654104134d9ef741958 Mon Sep 17 00:00:00 2001 From: Renaud Le Gac <renaud.legac@free.fr> Date: Sat, 17 Dec 2011 18:09:36 +0100 Subject: [PATCH] Add the possibility to define individual configurator in Node. --- languages/fr-fr.py | 5 +++++ models/widgets.py | 6 ++++-- modules/plugin_dbui/navtree.py | 20 +++++++++++++++----- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/languages/fr-fr.py b/languages/fr-fr.py index d8f62340..f1a50228 100644 --- a/languages/fr-fr.py +++ b/languages/fr-fr.py @@ -26,6 +26,10 @@ 'Id': 'Id', 'Last Page': 'Dernière Page', 'Max Records': 'Max Records', +'My Date': 'My Date', +'My Int': 'My Int', +'My List': 'My List', +'My String': 'My String', 'Pages': 'Pages', 'Project': 'Projet', 'Projects': 'Projets', @@ -57,6 +61,7 @@ 'publications': 'publications', 'publishers': 'éditeur', 'report_1': 'report_1', +'report_2': 'report_2', 'reports': 'rapports', 'select publication for a given year': 'selectionne les publication pour une année', 'select publications for a given CPPM author': 'selectionne les publications pour un auteur du CPPM', diff --git a/models/widgets.py b/models/widgets.py index b754a334..71d67aba 100755 --- a/models/widgets.py +++ b/models/widgets.py @@ -185,8 +185,10 @@ formNode = dbui.Node(T('Forms'), db.tables, cfgSvc.get_form) gridNode = dbui.Node(T('Tables'), db.tables, cfgSvc.get_grid) reportNode = dbui.Node(T('Reports'), - {'report_1': URL(c="reports", f="report_1")}, - dbui.cfg_configurable_url_panel) + {'report_1': URL(c="reports", f="report_1"), + 'report_2': URL(c="reports", f="report_1")}, + dbui.cfg_url_panel, + configurators={'report_2': dbui.cfg_configurable_url_panel}) viewportModifier = dbui.ViewportModifier() viewportModifier.add_node(formNode, gridNode, reportNode) diff --git a/modules/plugin_dbui/navtree.py b/modules/plugin_dbui/navtree.py index cab398ab..4be6abe4 100644 --- a/modules/plugin_dbui/navtree.py +++ b/modules/plugin_dbui/navtree.py @@ -70,8 +70,9 @@ class Node(object): target widget. It is a function getting the leave names, its attributes (dictionary value) and returning a dictionary. + Dedicated configurator can be setup for each node if needed. """ - def __init__(self, text, leaves, configurator, hidden=[]): + def __init__(self, text, leaves, configurator, configurators={}, hidden=[]): """Constructor of the node text @@ -82,11 +83,16 @@ class Node(object): will be used as leaf names configurator + The default configurator apply to all leaves. Reference to a function accepting either a leave name or a leave name and the dictionary value. The function return the configuration dictionary for the ExtJS widget. The function defines the type of widget. - + + configurators + A dictionary with references to configurator. + It can be used to associate a different configurator to + each leaf. The key is the leaf name. hidden List of leaves to be hidden. It contains leaves names @@ -111,15 +117,19 @@ class Node(object): leaf = cvt[tr_leaf] if leaf in hidden: continue + + func = configurator + if leaf in configurators: + func = configurators[leaf] if isinstance(leaves, (list, tuple)): - self.add_children(tr_leaf, configurator(leaf)) + self._add_children(tr_leaf, func(leaf)) elif isinstance(leaves, dict): - self.add_children(tr_leaf, configurator(leaf, leaves[leaf])) + self._add_children(tr_leaf, func(leaf, leaves[leaf])) - def add_children(self, text, cfg): + def _add_children(self, text, cfg): """ Add a child (leaf) to the node. text -- GitLab