Commit 490b8f5f authored by Nicolas Delaby's avatar Nicolas Delaby

Replace manualy computed dictionary by dynamic method of catalog object isValidColumn.

This allows to recognize automatic related_keys when they are used.

isValidColumn is transactional safe, cached and consistent with RelatedKey API

This improvement is similar as r42716


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@44063 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 8ec7905e
...@@ -110,12 +110,13 @@ class ExclusionTuple(tuple): ...@@ -110,12 +110,13 @@ class ExclusionTuple(tuple):
""" """
pass pass
def getValidCriterionDict(worklist_match_dict, acceptable_key_dict, def getValidCriterionDict(worklist_match_dict, sql_catalog,
workflow_worklist_key): workflow_worklist_key):
valid_criterion_dict = {} valid_criterion_dict = {}
metadata = None metadata = None
isValidColumn = sql_catalog.isValidColumn
for criterion_id, criterion_value in worklist_match_dict.iteritems(): for criterion_id, criterion_value in worklist_match_dict.iteritems():
if criterion_id in acceptable_key_dict: if isValidColumn(criterion_id):
if isinstance(criterion_value, tuple): if isinstance(criterion_value, tuple):
criterion_value = list(criterion_value) criterion_value = list(criterion_value)
assert criterion_id not in valid_criterion_dict assert criterion_id not in valid_criterion_dict
...@@ -141,7 +142,7 @@ def updateWorklistSetDict(worklist_set_dict, workflow_worklist_key, valid_criter ...@@ -141,7 +142,7 @@ def updateWorklistSetDict(worklist_set_dict, workflow_worklist_key, valid_criter
worklist_set_dict[worklist_set_dict_key]\ worklist_set_dict[worklist_set_dict_key]\
[workflow_worklist_key] = valid_criterion_dict [workflow_worklist_key] = valid_criterion_dict
def groupWorklistListByCondition(worklist_dict, acceptable_key_dict, def groupWorklistListByCondition(worklist_dict, sql_catalog,
getSecurityUidListAndRoleColumnDict=None): getSecurityUidListAndRoleColumnDict=None):
""" """
Get a list of dict of WorklistVariableMatchDict grouped by compatible Get a list of dict of WorklistVariableMatchDict grouped by compatible
...@@ -216,7 +217,7 @@ def groupWorklistListByCondition(worklist_dict, acceptable_key_dict, ...@@ -216,7 +217,7 @@ def groupWorklistListByCondition(worklist_dict, acceptable_key_dict,
role_column_dict.iteritems(): role_column_dict.iteritems():
valid_criterion_dict, metadata = getValidCriterionDict( valid_criterion_dict, metadata = getValidCriterionDict(
worklist_match_dict=worklist_match_dict, worklist_match_dict=worklist_match_dict,
acceptable_key_dict=acceptable_key_dict, sql_catalog=sql_catalog,
workflow_worklist_key=workflow_worklist_key) workflow_worklist_key=workflow_worklist_key)
if metadata is not None: if metadata is not None:
metadata_dict[workflow_worklist_key] = metadata metadata_dict[workflow_worklist_key] = metadata
...@@ -467,16 +468,12 @@ def WorkflowTool_listActions(self, info=None, object=None, src__=False): ...@@ -467,16 +468,12 @@ def WorkflowTool_listActions(self, info=None, object=None, src__=False):
def _getWorklistActionList(): def _getWorklistActionList():
worklist_result_dict = {} worklist_result_dict = {}
sql_catalog = portal_catalog.getSQLCatalog() sql_catalog = portal_catalog.getSQLCatalog()
acceptable_key_dict = sql_catalog.getColumnMap().copy()
for related_key in sql_catalog.getSQLCatalogRelatedKeyList():
related_key = related_key.split('|')
acceptable_key_dict[related_key[0].strip()] = related_key[1].strip()
# Get a list of dict of WorklistVariableMatchDict grouped by compatible # Get a list of dict of WorklistVariableMatchDict grouped by compatible
# conditions # conditions
(worklist_list_grouped_by_condition, worklist_metadata) = \ (worklist_list_grouped_by_condition, worklist_metadata) = \
groupWorklistListByCondition( groupWorklistListByCondition(
worklist_dict=worklist_dict, worklist_dict=worklist_dict,
acceptable_key_dict=acceptable_key_dict, sql_catalog=sql_catalog,
getSecurityUidListAndRoleColumnDict=\ getSecurityUidListAndRoleColumnDict=\
getSecurityUidListAndRoleColumnDict) getSecurityUidListAndRoleColumnDict)
if src__: if src__:
...@@ -609,9 +606,6 @@ def WorkflowTool_refreshWorklistCache(self): ...@@ -609,9 +606,6 @@ def WorkflowTool_refreshWorklistCache(self):
portal_catalog = getToolByName(self, 'portal_catalog') portal_catalog = getToolByName(self, 'portal_catalog')
search_result = portal_catalog.unrestrictedSearchResults search_result = portal_catalog.unrestrictedSearchResults
sql_catalog = portal_catalog.getSQLCatalog() sql_catalog = portal_catalog.getSQLCatalog()
acceptable_key_dict = sql_catalog.getColumnMap()
# XXX: those hardcoded lists should be grabbed from the table dynamicaly
# (and cached).
table_column_id_set = ImmutableSet( table_column_id_set = ImmutableSet(
[COUNT_COLUMN_TITLE] + self.Base_getWorklistTableColumnIDList()) [COUNT_COLUMN_TITLE] + self.Base_getWorklistTableColumnIDList())
security_column_id_list = ['security_uid'] + \ security_column_id_list = ['security_uid'] + \
...@@ -620,7 +614,7 @@ def WorkflowTool_refreshWorklistCache(self): ...@@ -620,7 +614,7 @@ def WorkflowTool_refreshWorklistCache(self):
(worklist_list_grouped_by_condition, worklist_metadata) = \ (worklist_list_grouped_by_condition, worklist_metadata) = \
groupWorklistListByCondition( groupWorklistListByCondition(
worklist_dict=worklist_dict, worklist_dict=worklist_dict,
acceptable_key_dict=acceptable_key_dict) sql_catalog=sql_catalog)
assert COUNT_COLUMN_TITLE in table_column_id_set assert COUNT_COLUMN_TITLE in table_column_id_set
for grouped_worklist_dict in worklist_list_grouped_by_condition: for grouped_worklist_dict in worklist_list_grouped_by_condition:
# Generate the query for this worklist_list # Generate the query for this worklist_list
......
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