Commit 57ba3aee authored by Jean-Paul Smets's avatar Jean-Paul Smets

Added support for simple types (ex. int) passed as arguments as well as...

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
parent 9cc514c4
...@@ -106,6 +106,12 @@ def manage_addSQLCatalog(self, id, title, ...@@ -106,6 +106,12 @@ def manage_addSQLCatalog(self, id, title,
if REQUEST is not None: if REQUEST is not None:
return self.manage_main(self, REQUEST,update_menu=1) 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): class UidBuffer(TM):
"""Uid Buffer class caches a list of reserved uids in a transaction-safe way.""" """Uid Buffer class caches a list of reserved uids in a transaction-safe way."""
...@@ -222,6 +228,17 @@ class Query(QueryMixin): ...@@ -222,6 +228,17 @@ class Query(QueryMixin):
def getSearchMode(self): def getSearchMode(self):
return self.search_mode 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, def asSQLExpression(self, key_alias_dict=None,
keyword_search_keys=None, keyword_search_keys=None,
full_text_search_keys=None, full_text_search_keys=None,
...@@ -263,10 +280,16 @@ class Query(QueryMixin): ...@@ -263,10 +280,16 @@ class Query(QueryMixin):
where_expression.append("%s >= '%s' and %s <= '%s'" % (key, query_min, key, query_max)) where_expression.append("%s >= '%s' and %s <= '%s'" % (key, query_min, key, query_max))
elif range_value == 'ngt' : elif range_value == 'ngt' :
where_expression.append("%s <= '%s'" % (key, query_max)) 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)): 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 value_list = value
if isinstance(value, basestring) or isinstance(value, DateTime): if isSimpleType(value) or isinstance(value, DateTime):
value_list = [value] value_list = [value]
# For security. # For security.
for value in value_list: for value in value_list:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment