From 57ba3aeecb353c19e0819ad9f6f6184cff8b6600 Mon Sep 17 00:00:00 2001 From: Jean-Paul Smets <jp@nexedi.com> Date: Mon, 12 Mar 2007 10:10:31 +0000 Subject: [PATCH] Added support for simple types (ex. int) passed as arguments as well as analysis of OR keyword in a string so that it is possible to pass mutliple values through a single string. git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@13339 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ZSQLCatalog/SQLCatalog.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/product/ZSQLCatalog/SQLCatalog.py b/product/ZSQLCatalog/SQLCatalog.py index c3a415746e..9095fdc4e1 100644 --- a/product/ZSQLCatalog/SQLCatalog.py +++ b/product/ZSQLCatalog/SQLCatalog.py @@ -106,6 +106,12 @@ def manage_addSQLCatalog(self, id, title, if REQUEST is not None: return self.manage_main(self, REQUEST,update_menu=1) +def isSimpleType(value): + return isinstance(value, basestring) or \ + isinstance(value, int) or \ + isinstance(value, long) or \ + isinstance(value, float) + class UidBuffer(TM): """Uid Buffer class caches a list of reserved uids in a transaction-safe way.""" @@ -222,6 +228,17 @@ class Query(QueryMixin): def getSearchMode(self): return self.search_mode + def asSearchTextExpression(self): + # This will be the standard way to represent + # complex values in listbox. Some fixed + # point must be garanteed + value = self.value + if isSimpleType(value) or isinstance(value, DateTime): + return str(value) + elif isinstance(value, (list, tuple)): + value = map(lambda x:str(x), value) + return (' %s ' % self.operator).join(value) + def asSQLExpression(self, key_alias_dict=None, keyword_search_keys=None, full_text_search_keys=None, @@ -263,10 +280,16 @@ class Query(QueryMixin): where_expression.append("%s >= '%s' and %s <= '%s'" % (key, query_min, key, query_max)) elif range_value == 'ngt' : where_expression.append("%s <= '%s'" % (key, query_max)) - elif isinstance(value, basestring) or isinstance(value, DateTime) \ + elif isSimpleType(value) or isinstance(value, DateTime) \ or isinstance(value, (list, tuple)): + # Convert into lists any value which contain a ; + # Refer to _listGlobalActions DCWorkflow patch + # for example of use + if isinstance(value, basestring): + value = value.split('OR') + value = map(lambda x:x.strip(), value) value_list = value - if isinstance(value, basestring) or isinstance(value, DateTime): + if isSimpleType(value) or isinstance(value, DateTime): value_list = [value] # For security. for value in value_list: -- 2.30.9