From 024e43e491a7ad7bcb34610f774fe08f7680af2d Mon Sep 17 00:00:00 2001 From: Renaud Le Gac <legac@cppm.in2p3.fr> Date: Mon, 17 Nov 2014 18:55:37 +0100 Subject: [PATCH] Add the validator IS_IN_USET. --- modules/plugin_dbui/__init__.py | 1 + modules/plugin_dbui/validators.py | 42 +++++++++++++++++++++++++++++++ static/plugin_dbui/CHANGELOG | 3 ++- 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 modules/plugin_dbui/validators.py diff --git a/modules/plugin_dbui/__init__.py b/modules/plugin_dbui/__init__.py index 68d52b77..1522463d 100644 --- a/modules/plugin_dbui/__init__.py +++ b/modules/plugin_dbui/__init__.py @@ -82,6 +82,7 @@ from helper import (as_list, from mapper import map_default, map_tabpanel from navtree import Node from selector import Selector +from validators import IS_IN_USET from viewportmodifier import ViewportModifier UNDEF = 'undefined' diff --git a/modules/plugin_dbui/validators.py b/modules/plugin_dbui/validators.py new file mode 100644 index 00000000..1ea21311 --- /dev/null +++ b/modules/plugin_dbui/validators.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- +""" validators + +@author: R. Le Gac + +""" +from gluon.validators import IS_IN_SET + + +class IS_IN_USET(IS_IN_SET): + """IS_IN_SET validator but working with unicode string. + + """ + + def __init__(self, theset, **kwargs): + + myset = [] + + if isinstance(theset, (list, tuple)): + for el in theset: + if isinstance(el, unicode): + el = el.encode("utf-8") + myset.append(el) + + elif isinstance(theset, dict): + myset = {} + for key in theset: + if isinstance(key, unicode): + myset[key.encode("utf-8")] = theset[key] + else: + myset[key] = theset[key] + + IS_IN_SET.__init__(self, myset, **kwargs) + + + def __call__(self, value): + + if isinstance(value, unicode): + value = value.encode("utf-8") + + return IS_IN_SET.__call__(self, value) + \ No newline at end of file diff --git a/static/plugin_dbui/CHANGELOG b/static/plugin_dbui/CHANGELOG index 746eda15..a4a1e411 100644 --- a/static/plugin_dbui/CHANGELOG +++ b/static/plugin_dbui/CHANGELOG @@ -3,7 +3,8 @@ HEAD - Add the plugin App.grid.plugin.Export. - Mask the whole viewport during loading a PanelWithUrlSelector. - - Version information can be export via the plugin pGridExport. + - Data on version can be export via the plugin pGridExport. + - Add the validator IS_IN_USET. 0.6.1.7 (Sep 2014) - Use inline script and Ext.grid.Panel to display software versions -- GitLab