Commit 82b837de authored by Jean-Paul Smets's avatar Jean-Paul Smets

Initial implementation of scriptable keys

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@13015 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent e3e0789b
...@@ -201,7 +201,7 @@ class Query(QueryMixin): ...@@ -201,7 +201,7 @@ class Query(QueryMixin):
self.range = range self.range = range
self.search_mode = search_mode self.search_mode = search_mode
key_list = kw.keys() key_list = kw.keys()
if len(key_list)!=1: if len(key_list) != 1:
raise KeyError, 'Query must have only one key' raise KeyError, 'Query must have only one key'
self.key = key_list[0] self.key = key_list[0]
self.value = kw[self.key] self.value = kw[self.key]
...@@ -218,7 +218,8 @@ class Query(QueryMixin): ...@@ -218,7 +218,8 @@ class Query(QueryMixin):
def getSearchMode(self): def getSearchMode(self):
return self.search_mode return self.search_mode
def asSQLExpression(self,key_alias_dict=None,keyword_search_keys=None, def asSQLExpression(self, key_alias_dict=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):
""" """
...@@ -1736,6 +1737,14 @@ class Catalog( Folder, ...@@ -1736,6 +1737,14 @@ class Catalog( Folder,
new_kw[k]['query'] = v new_kw[k]['query'] = v
kw = new_kw kw = new_kw
# Initialise Scriptable Dict
scriptable_key_dict = {}
for t in self.sql_catalog_scriptable_keys:
t = t.split('|')
key = t[0].strip()
method_id = t[1].strip()
scriptable_key_dict[key] = method_id
# Build the list of Queries and ComplexQueries # Build the list of Queries and ComplexQueries
query_dict = {} query_dict = {}
key_list = [] # the list of column keys key_list = [] # the list of column keys
...@@ -1745,19 +1754,23 @@ class Catalog( Folder, ...@@ -1745,19 +1754,23 @@ class Catalog( Folder,
value = kw[key] value = kw[key]
current_query = None current_query = None
new_query_dict = {} new_query_dict = {}
if isinstance(value,(Query,ComplexQuery)): if isinstance(value, (Query, ComplexQuery)):
current_query=value current_query = value
elif scriptable_key_dict.has_key(key):
# Turn this key into a query by invoking a script
method = getattr(self, scriptable_key_dict[key])
current_query = method(value)
else: else:
if isinstance(value,dict): if isinstance(value, dict):
for value_key in value.keys(): for value_key in value.keys():
if value_key=='query': if value_key == 'query':
new_query_dict[key]=value['query'] new_query_dict[key] = value['query']
else: else:
new_query_dict[value_key]=value[value_key] new_query_dict[value_key] = value[value_key]
else: else:
new_query_dict[key]=value new_query_dict[key] = value
current_query = Query(**new_query_dict) current_query = Query(**new_query_dict)
query_dict[key]=current_query query_dict[key] = current_query
key_list.extend(current_query.getSQLKeyList()) key_list.extend(current_query.getSQLKeyList())
if query is not None: if query is not None:
...@@ -1772,6 +1785,7 @@ class Catalog( Folder, ...@@ -1772,6 +1785,7 @@ class Catalog( Folder,
sort_key = sort_info[0] sort_key = sort_info[0]
if sort_key not in key_list: if sort_key not in key_list:
key_list.append(sort_key) key_list.append(sort_key)
related_tuples = self.getSQLCatalogRelatedKeyList(key_list=key_list) related_tuples = self.getSQLCatalogRelatedKeyList(key_list=key_list)
# Define related maps # Define related maps
......
...@@ -41,3 +41,5 @@ def initialize(context): ...@@ -41,3 +41,5 @@ def initialize(context):
context.registerHelp() context.registerHelp()
context.registerHelpTitle('Zope Help') context.registerHelpTitle('Zope Help')
from AccessControl import ModuleSecurityInfo, ClassSecurityInfo
ModuleSecurityInfo('Products.ZSQLCatalog.SQLCatalog').declarePublic('ComplexQuery', 'Query')
\ No newline at end of file
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