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":
sql_format = "%Y-%m-%d"
if to_date is not None:
to_date = atTheEndOfPeriod(to_date, period=aggregation_level)
params = {"creation_date":(from_date, to_date)}
query=None
count_kw = {}
if from_date is not None and to_date is not None:
params = {"creation_date":(from_date, to_date)}
query = Query(range="minmax", **params)
count_kw['creation_date'] = {
'range': 'minmax',
'query': (from_date, to_date),
}
elif from_date is not None:
params = {"creation_date":from_date}
query = Query(range="min", **params)
count_kw['creation_date'] = {
'range': 'min',
'query': from_date,
}
elif to_date is not None:
params = {"creation_date":to_date}
query = Query(range="max", **params)
count_kw['creation_date'] = {
'range': 'max',
'query': to_date,
}
select_expression = {'date' : 'DATE_FORMAT(creation_date, "%s")'%sql_format, 'portal_type' : None}
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())
result_list = context.portal_catalog.countResults(select_expression=select_expression,
portal_type=portal_type_list,limit=None,
owner=reference,query=query,
group_by_expression=group_by)
owner=reference,
group_by_expression=group_by,
**count_kw)
# build result dict per portal_type then period
portal_type_count_dict = {}
......
......@@ -8,21 +8,27 @@ aggregation_level = request.get('aggregation_level', None)
if to_date is not None:
to_date = atTheEndOfPeriod(to_date, period=aggregation_level)
# build query based on dates
query=None
if from_date is not None and to_date is not None:
params = {"delivery.start_date":(from_date, to_date)}
query = Query(range="minmax", **params)
catalog_kw = {}
if from_date is not None and to_date is not None:
catalog_kw['delivery.start_date'] = {
'range': 'minmax',
'query': (from_date, to_date),
}
elif from_date is not None:
params = {"delivery.start_date":from_date}
query = Query(range="min", **params)
catalog_kw['delivery.start_date'] = {
'range': 'min',
'query': from_date,
}
elif to_date is not None:
params = {"delivery.start_date":to_date}
query = Query(range="max", **params)
catalog_kw['delivery.start_date'] = {
'range': 'max',
'query': to_date,
}
event_type_list = portal.getPortalEventTypeList()
# 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)
dest_event_list = portal.portal_catalog(portal_type=event_type_list, default_destination_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(), **catalog_kw)
event_list = list(source_event_list)+list(dest_event_list)
......
......@@ -31,25 +31,31 @@ elif aggregation_level == "week":
sql_format = "%Y-%u"
elif aggregation_level == "day":
sql_format = "%Y-%m-%d"
params = {"creation_date":(from_date, to_date)}
query=None
count_kw = {}
if from_date is not None and to_date is not None:
params = {"creation_date":(from_date, to_date)}
query = Query(range="minngt", **params)
count_kw['creation_date'] = {
'range': 'minngt',
'query': (from_date, to_date),
}
elif from_date is not None:
params = {"creation_date":from_date}
query = Query(range="min", **params)
count_kw['creation_date'] = {
'range': 'min',
'query': from_date,
}
elif to_date is not None:
params = {"creation_date":to_date}
query = Query(range="ngt", **params)
count_kw['creation_date'] = {
'range': 'ngt',
'query': to_date,
}
select_expression = {'date' : '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
result_list = context.portal_catalog.countResults(select_expression=select_expression,
portal_type=portal_type_list,limit=None,
owner=context.Person_getUserId(),query=query,
group_by_expression=group_by)
owner=context.Person_getUserId(),
group_by_expression=group_by,
**count_kw)
# build result dict per portal_type then period
period_count_dict = {}
......
from Products.ZSQLCatalog.SQLCatalog import Query
portal = context.getPortalObject()
category_tool = portal.portal_categories
......@@ -54,17 +52,21 @@ elif aggregation_level == "week":
elif aggregation_level == "day":
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:
params = {"delivery.start_date": (from_date, at_date)}
query = Query(range="minngt", **params)
catalog_params['delivery.start_date'] = {
'range': 'minngt',
'query': (from_date, at_date),
}
elif from_date is not None:
params = {"delivery.start_date": from_date}
query = Query(range="min", **params)
catalog_params['delivery.start_date'] = {
'range': 'min',
'query': from_date,
}
elif at_date is not None:
params = {"delivery.start_date": at_date}
query = Query(range="ngt", **params)
catalog_params['delivery.start_date'] = {
'range': 'ngt',
'query': at_date,
}
select_params = {"select_list" : ['source_section_title', 'destination_section_title',
'delivery.start_date']}
......@@ -86,7 +88,6 @@ portal.portal_catalog.activate(tag=tag).searchAndActivate(
'tag' : tag,
},
# All SQL Params
query=query,
portal_type=doc_portal_type,
simulation_state=simulation_state,
packet_size=1000,
......
......@@ -28,13 +28,12 @@ for portal_type in context.allowedContentTypes():
add(state_var)
column_list = ['portal_type'] + list(state_variable_set)
COUNT = 'count(*)'
search_folder_kw = {}
if use_selection:
selection_kw = portal.portal_selections.getSelectionParamsFor(selection_name).copy()
selection_kw.pop('limit', None)
query = portal.portal_catalog.getSQLCatalog().buildQuery(selection_kw)
else:
query = None
for line in context.searchFolder(group_by=column_list, select_list=[COUNT] + column_list, query=query):
search_folder_kw['query'] = portal.portal_catalog.getSQLCatalog().buildQuery(selection_kw)
for line in context.searchFolder(group_by=column_list, select_list=[COUNT] + column_list, **search_folder_kw):
portal_type = line.portal_type
count = getattr(line, COUNT)
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