Commit 2163fa7c authored by Vincent Pelletier's avatar Vincent Pelletier

all: Do not pass query=None to catalog.

"query" argument is not supposed to be different from any other
argument (argument name is [pseudo-]column name, unknown coluns are
rejected, and "None" means "IS NULL" SQL comparison), but is accidentally
special-cased in ERP5Catalog. This special-casing is to be removed, so
update all callers relying on this glitch.
Also, avoid using Query.
parent 7698284f
...@@ -31,17 +31,22 @@ elif aggregation_level == "day": ...@@ -31,17 +31,22 @@ elif aggregation_level == "day":
sql_format = "%Y-%m-%d" sql_format = "%Y-%m-%d"
if to_date is not None: if to_date is not None:
to_date = atTheEndOfPeriod(to_date, period=aggregation_level) to_date = atTheEndOfPeriod(to_date, period=aggregation_level)
params = {"creation_date":(from_date, to_date)} count_kw = {}
query=None
if from_date is not None and to_date is not None: if from_date is not None and to_date is not None:
params = {"creation_date":(from_date, to_date)} count_kw['creation_date'] = {
query = Query(range="minmax", **params) 'range': 'minmax',
'query': (from_date, to_date),
}
elif from_date is not None: elif from_date is not None:
params = {"creation_date":from_date} count_kw['creation_date'] = {
query = Query(range="min", **params) 'range': 'min',
'query': from_date,
}
elif to_date is not None: elif to_date is not None:
params = {"creation_date":to_date} count_kw['creation_date'] = {
query = Query(range="max", **params) 'range': 'max',
'query': to_date,
}
select_expression = {'date' : 'DATE_FORMAT(creation_date, "%s")'%sql_format, 'portal_type' : None} select_expression = {'date' : 'DATE_FORMAT(creation_date, "%s")'%sql_format, 'portal_type' : None}
group_by = ['DATE_FORMAT(creation_date, "%s")' % sql_format, 'portal_type'] group_by = ['DATE_FORMAT(creation_date, "%s")' % sql_format, 'portal_type']
...@@ -49,8 +54,9 @@ group_by = ['DATE_FORMAT(creation_date, "%s")' % sql_format, 'portal_type'] ...@@ -49,8 +54,9 @@ group_by = ['DATE_FORMAT(creation_date, "%s")' % sql_format, 'portal_type']
reference = kw.get('person_reference_list', context.Person_getUserId()) reference = kw.get('person_reference_list', context.Person_getUserId())
result_list = context.portal_catalog.countResults(select_expression=select_expression, result_list = context.portal_catalog.countResults(select_expression=select_expression,
portal_type=portal_type_list,limit=None, portal_type=portal_type_list,limit=None,
owner=reference,query=query, owner=reference,
group_by_expression=group_by) group_by_expression=group_by,
**count_kw)
# build result dict per portal_type then period # build result dict per portal_type then period
portal_type_count_dict = {} portal_type_count_dict = {}
......
...@@ -8,21 +8,27 @@ aggregation_level = request.get('aggregation_level', None) ...@@ -8,21 +8,27 @@ aggregation_level = request.get('aggregation_level', None)
if to_date is not None: if to_date is not None:
to_date = atTheEndOfPeriod(to_date, period=aggregation_level) to_date = atTheEndOfPeriod(to_date, period=aggregation_level)
# build query based on dates # build query based on dates
query=None catalog_kw = {}
if from_date is not None and to_date is not None: if from_date is not None and to_date is not None:
params = {"delivery.start_date":(from_date, to_date)} catalog_kw['delivery.start_date'] = {
query = Query(range="minmax", **params) 'range': 'minmax',
'query': (from_date, to_date),
}
elif from_date is not None: elif from_date is not None:
params = {"delivery.start_date":from_date} catalog_kw['delivery.start_date'] = {
query = Query(range="min", **params) 'range': 'min',
'query': from_date,
}
elif to_date is not None: elif to_date is not None:
params = {"delivery.start_date":to_date} catalog_kw['delivery.start_date'] = {
query = Query(range="max", **params) 'range': 'max',
'query': to_date,
}
event_type_list = portal.getPortalEventTypeList() event_type_list = portal.getPortalEventTypeList()
# get events where user is either source or destination # get events where user is either source or destination
source_event_list = portal.portal_catalog(portal_type=event_type_list, default_source_uid=context.getUid(),query=query) source_event_list = portal.portal_catalog(portal_type=event_type_list, default_source_uid=context.getUid(), **catalog_kw)
dest_event_list = portal.portal_catalog(portal_type=event_type_list, default_destination_uid=context.getUid(),query=query) dest_event_list = portal.portal_catalog(portal_type=event_type_list, default_destination_uid=context.getUid(), **catalog_kw)
event_list = list(source_event_list)+list(dest_event_list) event_list = list(source_event_list)+list(dest_event_list)
......
...@@ -31,25 +31,31 @@ elif aggregation_level == "week": ...@@ -31,25 +31,31 @@ elif aggregation_level == "week":
sql_format = "%Y-%u" sql_format = "%Y-%u"
elif aggregation_level == "day": elif aggregation_level == "day":
sql_format = "%Y-%m-%d" sql_format = "%Y-%m-%d"
params = {"creation_date":(from_date, to_date)} count_kw = {}
query=None
if from_date is not None and to_date is not None: if from_date is not None and to_date is not None:
params = {"creation_date":(from_date, to_date)} count_kw['creation_date'] = {
query = Query(range="minngt", **params) 'range': 'minngt',
'query': (from_date, to_date),
}
elif from_date is not None: elif from_date is not None:
params = {"creation_date":from_date} count_kw['creation_date'] = {
query = Query(range="min", **params) 'range': 'min',
'query': from_date,
}
elif to_date is not None: elif to_date is not None:
params = {"creation_date":to_date} count_kw['creation_date'] = {
query = Query(range="ngt", **params) 'range': 'ngt',
'query': to_date,
}
select_expression = {'date' : 'DATE_FORMAT(creation_date, "%s")'%sql_format} select_expression = {'date' : 'DATE_FORMAT(creation_date, "%s")'%sql_format}
group_by = ['DATE_FORMAT(creation_date, "%s")' % sql_format,] group_by = ['DATE_FORMAT(creation_date, "%s")' % sql_format,]
# count number of object created by the user for each type of document # count number of object created by the user for each type of document
result_list = context.portal_catalog.countResults(select_expression=select_expression, result_list = context.portal_catalog.countResults(select_expression=select_expression,
portal_type=portal_type_list,limit=None, portal_type=portal_type_list,limit=None,
owner=context.Person_getUserId(),query=query, owner=context.Person_getUserId(),
group_by_expression=group_by) group_by_expression=group_by,
**count_kw)
# build result dict per portal_type then period # build result dict per portal_type then period
period_count_dict = {} period_count_dict = {}
......
from Products.ZSQLCatalog.SQLCatalog import Query
portal = context.getPortalObject() portal = context.getPortalObject()
category_tool = portal.portal_categories category_tool = portal.portal_categories
...@@ -54,17 +52,21 @@ elif aggregation_level == "week": ...@@ -54,17 +52,21 @@ elif aggregation_level == "week":
elif aggregation_level == "day": elif aggregation_level == "day":
date_format = "%Y-%m-%d" date_format = "%Y-%m-%d"
params = {"delivery.start_date":(from_date, at_date)}
query=None
if from_date is not None and at_date is not None: if from_date is not None and at_date is not None:
params = {"delivery.start_date": (from_date, at_date)} catalog_params['delivery.start_date'] = {
query = Query(range="minngt", **params) 'range': 'minngt',
'query': (from_date, at_date),
}
elif from_date is not None: elif from_date is not None:
params = {"delivery.start_date": from_date} catalog_params['delivery.start_date'] = {
query = Query(range="min", **params) 'range': 'min',
'query': from_date,
}
elif at_date is not None: elif at_date is not None:
params = {"delivery.start_date": at_date} catalog_params['delivery.start_date'] = {
query = Query(range="ngt", **params) 'range': 'ngt',
'query': at_date,
}
select_params = {"select_list" : ['source_section_title', 'destination_section_title', select_params = {"select_list" : ['source_section_title', 'destination_section_title',
'delivery.start_date']} 'delivery.start_date']}
...@@ -86,7 +88,6 @@ portal.portal_catalog.activate(tag=tag).searchAndActivate( ...@@ -86,7 +88,6 @@ portal.portal_catalog.activate(tag=tag).searchAndActivate(
'tag' : tag, 'tag' : tag,
}, },
# All SQL Params # All SQL Params
query=query,
portal_type=doc_portal_type, portal_type=doc_portal_type,
simulation_state=simulation_state, simulation_state=simulation_state,
packet_size=1000, packet_size=1000,
......
...@@ -28,13 +28,12 @@ for portal_type in context.allowedContentTypes(): ...@@ -28,13 +28,12 @@ for portal_type in context.allowedContentTypes():
add(state_var) add(state_var)
column_list = ['portal_type'] + list(state_variable_set) column_list = ['portal_type'] + list(state_variable_set)
COUNT = 'count(*)' COUNT = 'count(*)'
search_folder_kw = {}
if use_selection: if use_selection:
selection_kw = portal.portal_selections.getSelectionParamsFor(selection_name).copy() selection_kw = portal.portal_selections.getSelectionParamsFor(selection_name).copy()
selection_kw.pop('limit', None) selection_kw.pop('limit', None)
query = portal.portal_catalog.getSQLCatalog().buildQuery(selection_kw) search_folder_kw['query'] = portal.portal_catalog.getSQLCatalog().buildQuery(selection_kw)
else: for line in context.searchFolder(group_by=column_list, select_list=[COUNT] + column_list, **search_folder_kw):
query = None
for line in context.searchFolder(group_by=column_list, select_list=[COUNT] + column_list, query=query):
portal_type = line.portal_type portal_type = line.portal_type
count = getattr(line, COUNT) count = getattr(line, COUNT)
for state_variable in state_variable_set: for state_variable in state_variable_set:
......
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