diff --git a/models/db_widgets.py b/models/db_widgets.py index f887ea1e139addd5d5c5f00e18ef27fcbe2c0828..66ddfa77c037d8e2e6d2199b15bf0fc8df058b28 100644 --- a/models/db_widgets.py +++ b/models/db_widgets.py @@ -7,47 +7,55 @@ """ pgm = local_import('plugin_dbui') -pgm.define_field_set('publications', 'General', ['title', - 'authors', - 'id_collaborations', - 'id_publishers', - 'year', - 'volume', - 'first_page', - 'last_page', - 'e_print'], - collapsible=True, - flex=1, - defaults={'anchor': '100%'}, -# rowspan=2, - ) +fields = ['title', + 'authors', + 'id_collaborations', + 'id_publishers', + 'year', + 'volume', + 'first_page', + 'last_page', + 'e_print'] -pgm.define_field_set('publications', 'Conference', ['conference_title', - 'conference_url', - 'conference_start', - 'conference_end', - 'conference_town', - 'id_countries', - 'conference_speaker'], - collapsible=True, - flex=1, - defaults={'anchor': '100%'} - ) +pgm.customize_form_with_field_set('publications', 'General', fields, + collapsible=True, + flex=1, + defaults={'anchor': '100%'}, +# rowspan=2, + ) -pgm.define_field_set('publications', 'CPPM', ['authors_cppm', - 'id_teams', - 'id_categories_commission', - 'id_categories_aeres'], - collapsible=True, - flex=1, - defaults={'anchor': '100%'} - ) +fields = ['conference_title', + 'conference_url', + 'conference_start', + 'conference_end', + 'conference_town', + 'id_countries', + 'conference_speaker'] -pgm.define_field_set('publications', 'Rapport', ['report_numbers'], - collapsible=True, - flex=1, - defaults={'anchor': '100%'} - ) +pgm.customize_form_with_field_set('publications', 'Conference', fields, + collapsible=True, + flex=1, + defaults={'anchor': '100%'} + ) + + +fields = ['authors_cppm', + 'id_teams', + 'id_categories_commission', + 'id_categories_aeres'] + +pgm.customize_form_with_field_set('publications', 'CPPM', fields, + collapsible=True, + flex=1, + defaults={'anchor': '100%'} + ) + +fields = ['report_numbers'] +pgm.customize_form_with_field_set('publications', 'Rapport', fields, + collapsible=True, + flex=1, + defaults={'anchor': '100%'} + ) pgm.customize_form('publications', @@ -73,6 +81,6 @@ pgm.hidden_tables('publishers', 'categories_commission', 'collaborations', 'countries', - 'teams', +# 'teams', 'projects', 'publishers') \ No newline at end of file diff --git a/models/plugin_dbui.py b/models/plugin_dbui.py index 29649a95db93b88a7c70c9bd8a8aa217eb51cedf..43821e5e6068319267144f13e62d4387d17e1ba3 100644 --- a/models/plugin_dbui.py +++ b/models/plugin_dbui.py @@ -7,11 +7,11 @@ pgmodule = local_import('plugin_dbui') # define plugin parameters and their default value plugins = PluginManager('dbui', combined_fields=None, - customized_forms=None, - customized_grids=None, + customized_forms={}, + customized_grids={}, customized_viewport=None, - field_sets=None, - grid_filters=None, + field_sets={}, + grid_filters={}, hidden_tables=[], page_view='plugin_dbui.html', script_path='static/plugin_dbui/scripts', diff --git a/modules/plugin_dbui/__init__.py b/modules/plugin_dbui/__init__.py index a02e45f76b2e5f96ff5a944324fcd39ecc682b3a..01ce87ff841e54ec3907e12d200a384618f643c5 100644 --- a/modules/plugin_dbui/__init__.py +++ b/modules/plugin_dbui/__init__.py @@ -5,10 +5,10 @@ from cfgsvc import CfgSvc from dbsvc import DbSvc from tools import (customize_form, + customize_form_with_field_set, customize_grid, customize_viewport, define_combined_field, - define_field_set, define_grid_filter, define_wizard, hidden_tables) diff --git a/modules/plugin_dbui/cfgsvc.py b/modules/plugin_dbui/cfgsvc.py index 5a40c38358333e6161e38c43110e0405503bdb81..04e7613ff3947eec3ade18bfeb9a4dcc496dc927 100644 --- a/modules/plugin_dbui/cfgsvc.py +++ b/modules/plugin_dbui/cfgsvc.py @@ -177,7 +177,7 @@ class CfgSvc(object): # in all context, create, update, destroy. # It is add to the latest fieldset. - if self._field_sets and tablename in self._field_sets: + if tablename in self._field_sets: for fieldset in self._field_sets[tablename]: cfg = {'title': fieldset.title, @@ -274,10 +274,9 @@ class CfgSvc(object): di = {"xtype": "xentry", "model": model} - if self._customized_forms: - for el in (tablename, ALL): - if el in self._customized_forms: - di.update(self._customized_forms[el]) + for el in (tablename, ALL): + if el in self._customized_forms: + di.update(self._customized_forms[el]) return di @@ -290,10 +289,9 @@ class CfgSvc(object): formModel = {'xtype': 'xform', 'items': self._getFormModelItems(tablename)} - if self._customized_forms: - for el in (tablename, ALL): - if tablename in self._customized_forms: - formModel.update(self._customized_forms[tablename]) + for el in (tablename, ALL): + if tablename in self._customized_forms: + formModel.update(self._customized_forms[tablename]) model = {} model["colModel"] = self._getColumnsModel(tablename) @@ -304,10 +302,9 @@ class CfgSvc(object): di = {"xtype": "xgrid", "model": model} - if self._customized_grids: - for el in (tablename, ALL): - if el in self._customized_grids: - di.update(self._customized_grids[el]) + for el in (tablename, ALL): + if el in self._customized_grids: + di.update(self._customized_grids[el]) return di diff --git a/modules/plugin_dbui/tools.py b/modules/plugin_dbui/tools.py index 78e66c69f33df056e6892dc0e62f8634b76a5424..f67e13c12a70ae59e51b6a56906ef3e52364ec7c 100644 --- a/modules/plugin_dbui/tools.py +++ b/modules/plugin_dbui/tools.py @@ -15,6 +15,8 @@ def _init_tool(param, type='dict'): """ Return the plugin manager with the parameter param initialize as a dictionary, if it does not exist. + If can be a list if the type is equal to list. + """ p = PluginManager('dbui') if param not in p.dbui: @@ -24,9 +26,9 @@ def _init_tool(param, type='dict'): p.dbui[param] = [] return p - + def customize_form(tablename=None, **extjs): - """ Helper tool to apply Ext JS configuration parameters on form. + """ Helper tool to apply Ext JS configuration parameters on existing form. For details see the documentation of Ext.form.formPanel. The most interesting parameters are labelwidth, labelAlign, @@ -43,10 +45,40 @@ def customize_form(tablename=None, **extjs): p.dbui.customized_forms[key] = extjs +def customize_form_with_field_set(tablename, title, fields, **extjs): + """ Helper tool to customize an existing form with fieldset. + + tablename + name of the tablename + + title + title of the fieldset + + fields + list of field name, belonging to the tablename, + groups in the fieldset. + + extjs + Additional Ext JS configuration parameters + apply to the fieldset (See the documentation + of Ext.form.FieldSet) + + """ + p = _init_tool('field_sets') + if tablename not in p.dbui.field_sets: + p.dbui.field_sets[tablename] = [] + + di = Storage(title=title, fields=fields, extjs= extjs) + p.dbui.field_sets[tablename].append(di) + + def customize_grid(tablename=None, **extjs): - """ Helper tool to apply Ext JS configuration parameters on grid. + """ Helper tool to apply Ext JS configuration parameters on existing grid. For details see the documentation of Ext.grid.GridPanel. + The most interesting parameter is plugins: + pGridRowEditorContextMenu, pGridPaging, .... + If tablename is not define, the parameters will be apply to all grids. The order is the following apply first the table parameters then the general ones. @@ -72,30 +104,6 @@ def define_combined_field(): p = _init_tool('combined_fields') -def define_field_set(tablename, title, fields, **extjs): - """ Helper tool to define fieldSet in form. - tablename - name of the tablename - - title - title of the fieldset - - fields - list of field name belonging to the tablename - - extjs - Ext JS configuration parameters - See the documentation of Ext.form.FieldSet - - """ - p = _init_tool('field_sets') - if tablename not in p.dbui.field_sets: - p.dbui.field_sets[tablename] = [] - - di = Storage(title=title, fields=fields, extjs= extjs) - p.dbui.field_sets[tablename].append(di) - - def define_grid_filter(): """ Helper tool to define filter associate to grid. @@ -111,7 +119,7 @@ def define_wizard(): def hidden_tables(*args): - """ Helper tools to define a set of tables hidden in the viewport. + """ Helper tools to define a set of tables to be hidden in the viewport. """ p = _init_tool('hidden_tables', 'list')