Commit d8fe72b5 authored by Vincent Pelletier's avatar Vincent Pelletier

all: Stop using *_expression catalog arguments.

These are a bit more complex, there are more to come.
parent c208c12d
...@@ -47,15 +47,13 @@ elif to_date is not None: ...@@ -47,15 +47,13 @@ elif to_date is not None:
'range': 'max', 'range': 'max',
'query': to_date, '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']
# 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
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_dict={'date': 'DATE_FORMAT(creation_date, "%s")' % sql_format, 'portal_type': None},
portal_type=portal_type_list,limit=None, portal_type=portal_type_list,limit=None,
owner=reference, owner=reference,
group_by_expression=group_by, group_by=['DATE_FORMAT(creation_date, "%s")' % sql_format, 'portal_type'],
**count_kw) **count_kw)
# build result dict per portal_type then period # build result dict per portal_type then period
......
...@@ -33,11 +33,11 @@ if context.Person_getUserId() not in (None, ""): ...@@ -33,11 +33,11 @@ if context.Person_getUserId() not in (None, ""):
selection_columns = [('document_type', "Document Type")] selection_columns = [('document_type', "Document Type")]
if from_date is None: if from_date is None:
# get the minimum creation date in catalog # get the minimum creation date in catalog
select_expression = "MIN(creation_date)" from_date = context.portal_catalog(
group_by = "creation_date" select_list=['creation_date'],
from_date = DateTime(context.portal_catalog(select_expression=select_expression, sort_on=[['creation_date', 'ASC']],
group_by_expression=group_by, limit=1,
limit=1)[0][2]) )[0].creation_date
# get period list between given date # get period list between given date
interval_list_dict = getIntervalListBetweenDates(from_date=from_date, to_date=to_date, interval_list_dict = getIntervalListBetweenDates(from_date=from_date, to_date=to_date,
keys={'year':aggregation_level=="year", keys={'year':aggregation_level=="year",
......
...@@ -47,14 +47,12 @@ elif to_date is not None: ...@@ -47,14 +47,12 @@ elif to_date is not None:
'range': 'ngt', 'range': 'ngt',
'query': to_date, '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 # 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_dict={'date': 'DATE_FORMAT(creation_date, "%s")' % sql_format},
portal_type=portal_type_list,limit=None, portal_type=portal_type_list,limit=None,
owner=context.Person_getUserId(), owner=context.Person_getUserId(),
group_by_expression=group_by, group_by=['DATE_FORMAT(creation_date, "%s")' % sql_format],
**count_kw) **count_kw)
# build result dict per portal_type then period # build result dict per portal_type then period
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
- if requested, filters result so that only the user's docs are returned - if requested, filters result so that only the user's docs are returned
- if requested, filters result to return only the newest versions - if requested, filters result to return only the newest versions
""" """
from Products.ZSQLCatalog.SQLCatalog import SimpleQuery, ComplexQuery
portal = context.getPortalObject() portal = context.getPortalObject()
query_kw = {} query_kw = {}
...@@ -49,25 +50,21 @@ for key in ('reference', 'version', 'language',): ...@@ -49,25 +50,21 @@ for key in ('reference', 'version', 'language',):
if value is not None: if value is not None:
query_kw[key] = value query_kw[key] = value
where_expression_list = [] query_list = []
creation_from = parsed_search_string.get('creation_from', None) creation_from = parsed_search_string.get('creation_from', None)
creation_to = parsed_search_string.get('creation_to', None) creation_to = parsed_search_string.get('creation_to', None)
modification_from = parsed_search_string.get('modification_from', None) modification_from = parsed_search_string.get('modification_from', None)
modification_to = parsed_search_string.get('modification_to', None) modification_to = parsed_search_string.get('modification_to', None)
if creation_from: if creation_from:
where_expression_list.append('catalog.creation_date >= "%s"' \ query_list.append(SimpleQuery(creation_date=creation_from.strftime('>=' + date_format)))
%creation_from.strftime(date_format))
if creation_to: if creation_to:
where_expression_list.append('catalog.creation_date <= "%s"' \ query_list.append(SimpleQuery(creation_date=creation_to.strftime('<=' + date_format)))
%creation_to.strftime(date_format))
if modification_from: if modification_from:
where_expression_list.append('catalog.modification_date >= "%s"' \ query_list.append(SimpleQuery(modification_date=modification_from.strftime('>=' + date_format)))
%modification_from.strftime(date_format))
if modification_to: if modification_to:
where_expression_list.append('catalog.modification_date <= "%s"' \ query_list.append(SimpleQuery(modification_date=modification_to.strftime('<=' + date_format)))
%modification_to.strftime(date_format)) if query_list:
if len(where_expression_list): query_kw['query'] = ComplexQuery(query_list, logical_operator='and')
query_kw['where_expression'] = ' AND '.join(where_expression_list)
if parsed_search_string.get('mine', None) is not None: if parsed_search_string.get('mine', None) is not None:
# user wants only his documents # user wants only his documents
......
...@@ -79,18 +79,18 @@ else: ...@@ -79,18 +79,18 @@ else:
Query(birth_date = [DateTime(person_start_date.year(), 1, 1), DateTime(person_start_date.year(), 12, 31),],range = 'minmax'), Query(birth_date = [DateTime(person_start_date.year(), 1, 1), DateTime(person_start_date.year(), 12, 31),],range = 'minmax'),
logical_operator = "AND"), logical_operator = "AND"),
logical_operator = "OR") logical_operator = "OR")
select_expression = \
"""((title ="%s"))AS result_order
""" % (person_title)
#select_expression = \ #select_expression = \
#"""((title ="%s") + (start_date ="%s") + (birthplace_city ="%s"))AS result_order #"""((title ="%s") + (start_date ="%s") + (birthplace_city ="%s"))AS result_order
#""" % (person_title, person_start_date, person_birthplace) #""" % (person_title, person_start_date, person_birthplace)
candidate_list = context.portal_catalog(portal_type = 'Person', candidate_list = sorted(
query = query, context.portal_catalog(
select_expression = select_expression, portal_type='Person',
sort_on = (('result_order', 'DESC', 'int'),), query=query,
select_expression_key = 'result_order') select_list=['title'],
),
key=lambda x: x.title == person_title
)
for candidate in candidate_list: for candidate in candidate_list:
candidate_first_name = candidate.getFirstName() candidate_first_name = candidate.getFirstName()
......
...@@ -37,18 +37,15 @@ if from_date is None: ...@@ -37,18 +37,15 @@ if from_date is None:
from Products.ZSQLCatalog.SQLCatalog import Query, NegatedQuery from Products.ZSQLCatalog.SQLCatalog import Query, NegatedQuery
kw = {"delivery.start_date" : None, "key":"DefaultKey"} kw = {"delivery.start_date" : None, "key":"DefaultKey"}
q = NegatedQuery(Query(**kw)) q = NegatedQuery(Query(**kw))
select_expression = "MIN(delivery.start_date)"
group_by = "delivery.start_date"
from_date = DateTime() from_date = DateTime()
result_list = context.portal_catalog( result_list = context.portal_catalog(
select_expression=select_expression, select_dict={'start_date': 'delivery.start_date'},
group_by_expression=group_by,
simulation_state=simulation_state, simulation_state=simulation_state,
portal_type=doc_portal_type, portal_type=doc_portal_type,
query=q, query=q,
limit=1) limit=1)
if result_list: if result_list:
from_date = DateTime(result_list[0][2]) from_date = DateTime(result_list[0].start_date)
# get period list between given date # get period list between given date
......
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