Commit 66baa551 authored by Jean-Paul Smets's avatar Jean-Paul Smets

Minor cosmetic changes. Also fixed the case when no parameters (kw) nor a...

Minor cosmetic changes. Also fixed the case when no parameters (kw) nor a query are passed to the catalog.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@13038 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 50d88cec
...@@ -79,6 +79,7 @@ except ImportError: ...@@ -79,6 +79,7 @@ except ImportError:
disableReadOnlyTransactionCache = doNothing disableReadOnlyTransactionCache = doNothing
UID_BUFFER_SIZE = 300 UID_BUFFER_SIZE = 300
RESERVED_KEY_LIST = ('where_expression', 'sort-on', 'sort_on', 'sort-order', 'sort_order', 'limit')
valid_method_meta_type_list = ('Z SQL Method', 'Script (Python)') valid_method_meta_type_list = ('Z SQL Method', 'Script (Python)')
...@@ -192,8 +193,8 @@ class Query(QueryMixin): ...@@ -192,8 +193,8 @@ class Query(QueryMixin):
""" """
This allow to define constraints on a sql column This allow to define constraints on a sql column
""" """
def __init__(self,format=None,operator=None,range=None, def __init__(self, format=None, operator=None, range=None,
search_mode=None,**kw): search_mode=None, **kw):
self.format = format self.format = format
if operator is None: if operator is None:
operator = 'OR' operator = 'OR'
...@@ -221,7 +222,7 @@ class Query(QueryMixin): ...@@ -221,7 +222,7 @@ class Query(QueryMixin):
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,
ignore_empty_string=1,stat__=0): ignore_empty_string=1, stat__=0):
""" """
Build the sql string Build the sql string
""" """
...@@ -1735,7 +1736,7 @@ class Catalog( Folder, ...@@ -1735,7 +1736,7 @@ class Catalog( Folder,
def buildSQLQuery(self, query_table='catalog', REQUEST=None, def buildSQLQuery(self, query_table='catalog', REQUEST=None,
ignore_empty_string=1, query=None, stat__=0, **kw): ignore_empty_string=1, query=None, stat__=0, **kw):
""" Builds a complex SQL query to simulate ZCalatog behaviour """ """ Builds a complex SQL query to simulate ZCatalog behaviour """
# Get search arguments: # Get search arguments:
if REQUEST is None and (kw is None or kw == {}): if REQUEST is None and (kw is None or kw == {}):
# We try to get the REQUEST parameter # We try to get the REQUEST parameter
...@@ -1744,8 +1745,8 @@ class Catalog( Folder, ...@@ -1744,8 +1745,8 @@ class Catalog( Folder,
except AttributeError: pass except AttributeError: pass
#LOG('SQLCatalog.buildSQLQuery, kw',0,kw) #LOG('SQLCatalog.buildSQLQuery, kw',0,kw)
# If kw is not set, then use REQUEST instead # If kw and query are not set, then use REQUEST instead
if kw is None or kw == {}: if query is None and (kw is None or kw == {}):
kw = REQUEST kw = REQUEST
acceptable_key_map = self.getColumnMap() acceptable_key_map = self.getColumnMap()
...@@ -1813,7 +1814,7 @@ class Catalog( Folder, ...@@ -1813,7 +1814,7 @@ class Catalog( Folder,
key_list = [] # the list of column keys key_list = [] # the list of column keys
key_alias_dict = {} key_alias_dict = {}
for key in kw.keys(): for key in kw.keys():
if key not in ('where_expression', 'sort-on', 'sort_on', 'sort-order', 'sort_order', 'limit'): if key not in RESERVED_KEY_LIST:
value = kw[key] value = kw[key]
current_query = None current_query = None
new_query_dict = {} new_query_dict = {}
...@@ -2006,7 +2007,7 @@ class Catalog( Folder, ...@@ -2006,7 +2007,7 @@ class Catalog( Folder,
if not key_alias_dict.has_key(key): if not key_alias_dict.has_key(key):
getNewKeyAndUpdateVariables(key) getNewKeyAndUpdateVariables(key)
if len(query_dict): if len(query_dict):
for key,query in query_dict.items(): for key, query in query_dict.items():
query_result = query.asSQLExpression(key_alias_dict=key_alias_dict, query_result = query.asSQLExpression(key_alias_dict=key_alias_dict,
full_text_search_keys=full_text_search_keys, full_text_search_keys=full_text_search_keys,
keyword_search_keys=keyword_search_keys, keyword_search_keys=keyword_search_keys,
...@@ -2107,23 +2108,16 @@ class Catalog( Folder, ...@@ -2107,23 +2108,16 @@ class Catalog( Folder,
""" Returns a list of brains from a set of constraints on variables """ """ Returns a list of brains from a set of constraints on variables """
# The used argument is deprecated and is ignored # The used argument is deprecated and is ignored
method = getattr(self, self.sql_search_results) method = getattr(self, self.sql_search_results)
# Return the result return self.queryResults(method, REQUEST=REQUEST, used=used, **kw)
kw['used'] = used
kw['REQUEST'] = REQUEST
return self.queryResults(method, **kw)
__call__ = searchResults __call__ = searchResults
def countResults(self, REQUEST=None, used=None, **kw): def countResults(self, REQUEST=None, used=None, stat__=1, **kw):
""" Builds a complex SQL where_expression to simulate ZCalatog behaviour """ """ Builds a complex SQL where_expression to simulate ZCalatog behaviour """
""" Returns the number of items which satisfy the where_expression """ """ Returns the number of items which satisfy the where_expression """
# Get the search method # Get the search method
method = getattr(self, self.sql_count_results) method = getattr(self, self.sql_count_results)
# Return the result return self.queryResults(method, REQUEST=REQUEST, used=used, stat__=stat__, **kw)
kw['used'] = used
kw['REQUEST'] = REQUEST
kw['stat__'] = 1
return self.queryResults(method, **kw)
def recordObjectList(self, path_list, catalog=1): def recordObjectList(self, path_list, catalog=1):
""" """
......
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