diff --git a/models/db_database.py b/models/db_database.py index 970b88c5bbce7409ed80ad7056f14effaef247b5..07d476b91094618357e7ebb252823d49029b6602 100644 --- a/models/db_database.py +++ b/models/db_database.py @@ -82,10 +82,7 @@ db.define_table("publications", default=1), SQLField("id_publishers", db.publishers, label='Publisher', default=1), - SQLField("year", "integer", notnull=True, - default=datetime.now().year, - widget={'xtype': 'numberfield', - 'maxValue': 2010}), + SQLField("year", "integer", notnull=True, default=datetime.now().year), SQLField("volume", "string", length=20, default=None), SQLField("first_page", "integer", default=None), SQLField("last_page", "integer", default=None), diff --git a/models/db_widgets.py b/models/db_widgets.py index 66ddfa77c037d8e2e6d2199b15bf0fc8df058b28..6beb14b9b95e950b76e8a916ac5aedc6c0cde03f 100644 --- a/models/db_widgets.py +++ b/models/db_widgets.py @@ -5,8 +5,11 @@ $Id$ """ +from datetime import datetime pgm = local_import('plugin_dbui') +pgm.customize_field('publications', 'year', maxValue=datetime.now().year) + fields = ['title', 'authors', 'id_collaborations', diff --git a/models/plugin_dbui.py b/models/plugin_dbui.py index 43821e5e6068319267144f13e62d4387d17e1ba3..584fde5a9ff1ac9bde889d1ba16a15af5c1b8aed 100644 --- a/models/plugin_dbui.py +++ b/models/plugin_dbui.py @@ -7,6 +7,7 @@ pgmodule = local_import('plugin_dbui') # define plugin parameters and their default value plugins = PluginManager('dbui', combined_fields=None, + customized_fields={}, customized_forms={}, customized_grids={}, customized_viewport=None, diff --git a/modules/plugin_dbui/__init__.py b/modules/plugin_dbui/__init__.py index 01ce87ff841e54ec3907e12d200a384618f643c5..e39ee6120d5b8200d031ca81e1c59b4b16023ccb 100644 --- a/modules/plugin_dbui/__init__.py +++ b/modules/plugin_dbui/__init__.py @@ -4,7 +4,8 @@ from cfgsvc import CfgSvc from dbsvc import DbSvc -from tools import (customize_form, +from tools import (customize_field, + customize_form, customize_form_with_field_set, customize_grid, customize_viewport, diff --git a/modules/plugin_dbui/cfgsvc.py b/modules/plugin_dbui/cfgsvc.py index 04e7613ff3947eec3ade18bfeb9a4dcc496dc927..008b542db4f54c37d4302ffcc39c25af6dc6444e 100644 --- a/modules/plugin_dbui/cfgsvc.py +++ b/modules/plugin_dbui/cfgsvc.py @@ -103,13 +103,9 @@ class CfgSvc(object): """ field = self._db[tablename][fieldname] cfg= {"name": encode_field(tablename, fieldname)} - - # custom widget (supersede all other definitions) - if field.widget: - cfg.update(field.widget) - + # foreign key - elif self._is_foreign_field(tablename, fieldname): + if self._is_foreign_field(tablename, fieldname): k_tablename, k_fieldname, k_key = \ self._get_foreign_data(tablename, fieldname) @@ -163,6 +159,11 @@ class CfgSvc(object): cfg["hideLabel"] = True cfg["readOnly"] = True + # customized field + if tablename in self._customized_fields and \ + fieldname in self._customized_fields[tablename]: + cfg.update(self._customized_fields[tablename][fieldname]) + return cfg diff --git a/modules/plugin_dbui/tools.py b/modules/plugin_dbui/tools.py index f67e13c12a70ae59e51b6a56906ef3e52364ec7c..e9db0335ad016be010001a6b35dcb0b4f0e06444 100644 --- a/modules/plugin_dbui/tools.py +++ b/modules/plugin_dbui/tools.py @@ -27,6 +27,17 @@ def _init_tool(param, type='dict'): return p +def customize_field(tablename, fieldname, **extjs): + """ Helper tool to customize an existing field by applying the + Ext JS configuration parameters. + + """ + p = _init_tool('customized_fields') + if tablename not in p.dbui.customized_fields: + p.dbui.customized_fields[tablename] = {} + p.dbui.customized_fields[tablename][fieldname] = extjs + + def customize_form(tablename=None, **extjs): """ Helper tool to apply Ext JS configuration parameters on existing form. For details see the documentation of Ext.form.formPanel.