Commit 1b25ac66 authored by Vincent Pelletier's avatar Vincent Pelletier Committed by Eteri

all: Stop using *_expression catalog arguments.

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