Commit 77a1b9ce authored by Vincent Pelletier's avatar Vincent Pelletier

WIP all: Stop using *_expression catalog arguments.

parent b1d92322
......@@ -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
......
......@@ -20,8 +20,8 @@ def getAvailableSubjectList(subject_list=(), container_uid=None):
"""
#log("In getAvailableSubjectList with container: %s subject_list: %s" % (container_uid, subject_list))
kw = dict(subject="!=",
select_expression="subject.subject",
group_by_expression="subject.subject",
select_list=["subject.subject"],
group_by=["subject.subject"],
#src__=1
)
if container_uid: kw['parent_uid'] = container_uid
......
......@@ -4,7 +4,7 @@ if depth == 0:
task_uid_list = context.portal_selections.getSelectionUidList(context=context, selection_name='task_module_selection')
person_result = context.portal_catalog(portal_type=["Person",],
source_related_uid=task_uid_list,
select_expression='relative_url, id, title',
select_list=['relative_url', 'id', 'title'],
sort_on = (('title','ascending'),))
person_dict = {}
......
......@@ -6,11 +6,11 @@ def Task_getRelatedSourceProject(depth, parent_relative_url=None):
task_uid_list = context.portal_selections.getSelectionUidList(context=context, selection_name='task_module_selection')
project_result = context.portal_catalog(portal_type=["Project", "Project Line"],
source_project_related_uid=task_uid_list,
select_expression='portal_type, relative_url, id, title',
select_list=['portal_type', 'relative_url', 'id', 'title'],
sort_on = (('title','ascending'),))
else:
project_result = context.portal_catalog(portal_type=["Project Line", "Project Milestones"],
select_expression='portal_type, relative_url, id, title',
select_list=['portal_type', 'relative_url', 'id', 'title'],
parent_relative_url=parent_relative_url,
sort_on = (('title','ascending'),))
# use a dict to store catalog result
......
......@@ -4,7 +4,7 @@ if depth == 0:
task_uid_list = context.portal_selections.getSelectionUidList(context=context, selection_name='task_report_module_selection')
person_result = context.portal_catalog(portal_type=["Person",],
source_related_uid=task_uid_list,
select_expression='portal_type, relative_url, id, title',
select_list=['portal_type', 'relative_url', 'id', 'title'],
sort_on = (('title','ascending'),))
person_dict = {}
person_list = []
......
......@@ -6,11 +6,11 @@ def Task_getRelatedSourceProject(depth, parent_relative_url=None):
task_uid_list = context.portal_selections.getSelectionUidList(context=context, selection_name='task_report_module_selection')
project_result = context.portal_catalog(portal_type=["Project", "Project Line"],
source_project_related_uid=task_uid_list,
select_expression='portal_type, relative_url, id, title',
select_list=['portal_type', 'relative_url', 'id', 'title'],
sort_on = (('title','ascending'),))
else:
project_result = context.portal_catalog(portal_type=["Project Line", "Project Milestones"],
select_expression='portal_type, relative_url, id, title',
select_list=['portal_type', 'relative_url', 'id', 'title'],
parent_relative_url=parent_relative_url,
sort_on = (('title','ascending'),))
# use a dict to store catalog result
......
......@@ -79,18 +79,18 @@ else:
Query(birth_date = [DateTime(person_start_date.year(), 1, 1), DateTime(person_start_date.year(), 12, 31),],range = 'minmax'),
operator = "AND"),
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()
......
......@@ -292,7 +292,7 @@ class OscommerceERP5NodeConduit(TioSafeBaseConduit):
address_list = document.searchFolder(
portal_type='Address',
sort_on=(['id', 'ASC'],),
where_expression='id != "default_address"',
id='!=default_address',
)
try:
address = address_list[address_index].getObject()
......@@ -385,7 +385,7 @@ class OscommerceERP5NodeConduit(TioSafeBaseConduit):
address_list = document.searchFolder(
portal_type='Address',
sort_on=(['id', 'ASC'], ),
where_expression='id != "default_address"',
id='!=default_address',
)
address_id = address_list[address_index].getId()
try:
......
......@@ -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
......
......@@ -19,7 +19,7 @@ def buildIndex(language=None):
from Products.ZSQLCatalog.SQLCatalog import NegatedQuery, Query
# Retrieve the different subjects in the catalog
subject_list = context.searchResults(
select_expression='subject, reference',
select_list=['subject', 'reference'],
query=NegatedQuery(Query(subject=None)),
language=language or '',
sort_on=(('subject', 'ascending'), ('title', 'ascending')),
......
......@@ -808,7 +808,7 @@ class SimulationTool(BaseTool):
if where_expression != '':
add_kw['where_expression'] = where_expression
add_kw['predicate_category.uid'] = '!=NULL'
add_kw['group_by_expression'] = 'uid'
add_kw['group_by'] = ['uid']
add_query = self.portal_catalog(**add_kw)
uid_list = []
for line in add_query:
......
......@@ -264,7 +264,7 @@ class TestSaleSupply(TestSupplyMixin, SubcontentReindexingWrapper,
kw = {}
kw['predicate.uid'] = supply_line.getUid()
kw['select_expression'] = 'predicate.start_date_range_min'
kw['select_list'] = ['predicate.start_date_range_min']
# check supply line in predicate table
result = self.catalog_tool(**kw)
......
......@@ -576,8 +576,8 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
security_uid_dict = {None: [x.security_uid for x in \
self.unrestrictedSearchResults(
allowedRolesAndUsers=allowedRolesAndUsers,
select_expression="security_uid",
group_by_expression="security_uid")] }
select_list=["security_uid"],
group_by=["security_uid"])] }
else:
# XXX: What with this string transformation ?! Souldn't it be done in
# dtml instead ? ... yes, but how to be bw compatible ?
......
......@@ -1367,11 +1367,11 @@ class ListBoxRenderer:
return DomainSelection(domain_dict = root_dict).__of__(self.getContext())
@lazyMethod
def getStatSelectExpression(self):
"""Return a string which expresses the information retrieved by SELECT for
def getStatSelectDict(self):
"""Return a dict which expresses the information retrieved by SELECT for
the statistics.
"""
select_expression_list = []
select_dict = {}
if self.showStat():
stats = self.getSelectionTool().getSelectionStats(self.getSelectionName(), REQUEST = self.request)
stat_column_list = self.getStatColumnList()
......@@ -1386,13 +1386,13 @@ class ListBoxRenderer:
if (column is not None) and (column[0] == column[1]):
try:
if stats[index] != ' ':
select_expression_list.append('%s(%s) AS %s' % (stats[index], sql, alias))
select_dict[alias] = '%s(%s)' % (stats[index], sql)
else:
select_expression_list.append("'' AS %s" % alias)
select_dict[alias] = "''"
except IndexError:
select_expression_list.append("'' AS %s" % alias)
select_dict[alias] = "''"
return ', '.join(select_expression_list)
return select_dict
def makeReportTreeList(self, root_dict = None, report_path = None, base_category = None, depth = 0,
unfolded_list = (), is_report_opened = True, sort_on = (('id', 'ASC'),),
......@@ -1618,7 +1618,7 @@ class ListBoxRenderer:
# First, get the statitics by the global stat method.
param_dict = self.getParamDict()
new_param_dict = param_dict.copy()
new_param_dict['select_expression'] = self.getStatSelectExpression()
new_param_dict['select_dict'] = self.getStatSelectDict()
selection = self.getSelection()
selection.edit(params = new_param_dict)
......@@ -1702,7 +1702,7 @@ class ListBoxRenderer:
selection = self.getSelection()
selection_tool = self.getSelectionTool()
report_list = selection.getReportList()
stat_select_expression = self.getStatSelectExpression()
stat_select_dict = self.getStatSelectDict()
stat_method = self.getStatMethod()
count_method = self.getCountMethod()
list_method = self.getListMethod()
......@@ -1768,9 +1768,9 @@ class ListBoxRenderer:
stat_method)
if report_tree.is_pure_summary and self.showStat():
# Push a new select_expression.
# Push a new select_dict.
new_param_dict = param_dict.copy()
new_param_dict['select_expression'] = stat_select_expression
new_param_dict['select_dict'] = stat_select_dict
selection.edit(params = new_param_dict)
# Query the stat.
......
......@@ -493,8 +493,8 @@ def WorkflowTool_listActions(self, info=None, object=None, src__=False):
sql_catalog.getSQLCatalogSecurityUidGroupsColumnsDict()
getSecurityUidDictAndRoleColumnDict = \
portal_catalog.getSecurityUidDictAndRoleColumnDict
search_result = getattr(self, "Base_getCountFromWorklistTable", None)
use_cache = search_result is not None
search_result_ = getattr(self, "Base_getCountFromWorklistTable", None)
use_cache = search_result_ is not None
if use_cache:
ignored_security_column_id_set = self._getWorklistIgnoredSecurityColumnSet()
ignored_security_uid_parameter_set = {x
......@@ -512,12 +512,26 @@ def WorkflowTool_listActions(self, info=None, object=None, src__=False):
ignored_security_uid_parameter_set:
security_uid_dict.pop(ignored_security_uid_parameter)
return security_uid_dict, role_column_dict, local_role_column_dict
select_expression_prefix = 'sum(`%s`) as %s' % (COUNT_COLUMN_TITLE, COUNT_COLUMN_TITLE)
count_column_expression = 'sum(`%s`)' % (COUNT_COLUMN_TITLE, )
# Prevent catalog from trying to join
getQuery = SimpleQuery
# BBB
def search_result(select_dict, group_by, query, limit, src__):
select_item_list = []
for alias, expression in select_dict.iteritems():
if expression is None:
expression = alias
select_item_list.append('%s AS %s' % (expression, alias))
return search_result_(
select_expression=','.join(select_item_list),
group_by_expression=','.join(group_by),
query=query,
limit=limit,
src__=src__,
)
else:
search_result = portal_catalog.unrestrictedSearchResults
select_expression_prefix = 'count(*) as %s' % (COUNT_COLUMN_TITLE, )
count_column_expression = 'count(*)'
# Let catalog join as needed
getQuery = lambda comparison_operator=None, **kw: AutoQuery(
operator=comparison_operator,
......@@ -544,18 +558,15 @@ def WorkflowTool_listActions(self, info=None, object=None, src__=False):
getQuery=getQuery,
grouped_worklist_dict=grouped_worklist_dict,
)
group_by_expression = ', '.join(total_criterion_id_list)
group_by = total_criterion_id_list
assert COUNT_COLUMN_TITLE not in total_criterion_id_list
# If required mapping method is not present on the query, assume it
# handles column mapping properly, and build a bare select
# expression.
select_expression = select_expression_prefix + ', ' \
+ group_by_expression
select_dict = dict.fromkeys(total_criterion_id_list)
select_dict[COUNT_COLUMN_TITLE] = count_column_expression
catalog_brain_result = []
try:
catalog_brain_result = search_result(
select_expression=select_expression,
group_by_expression=group_by_expression,
select_dict=select_dict,
group_by=group_by,
query=query,
limit=None,
src__=src__)
......@@ -684,14 +695,16 @@ def WorkflowTool_refreshWorklistCache(self):
for security_column_id in security_column_id_set:
assert security_column_id not in total_criterion_id_list
total_criterion_id_list.append(security_column_id)
group_by_expression = ', '.join(total_criterion_id_list)
group_by = total_criterion_id_list
assert COUNT_COLUMN_TITLE not in total_criterion_id_list
select_expression = 'count(*) as %s, %s' % (COUNT_COLUMN_TITLE,
group_by_expression)
search_result_kw = {'select_expression': select_expression,
'group_by_expression': group_by_expression,
'query': query,
'limit': None}
select_dict = dict.fromkeys(total_criterion_id_list)
select_dict[COUNT_COLUMN_TITLE] = 'count(*)'
search_result_kw = {
'select_dict': select_dict,
'group_by': group_by,
'query': query,
'limit': None,
}
#LOG('refreshWorklistCache', WARNING, 'Using query: %s' % \
# (search_result(src__=1, **search_result_kw), ))
catalog_brain_result = search_result(**search_result_kw)
......
......@@ -216,7 +216,7 @@ class EGOVUserManager(ERP5UserManager):
newSecurityManager(self, self.getUser(SUPER_USER))
try:
result = portal.portal_catalog.unrestrictedSearchResults(
select_expression='reference',
select_list=['reference'],
portal_type=self.portal_type_list, reference=login)
if len(result) != 1: # we won't proceed with groups
if len(result) > 1: # configuration is screwed
......
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