Commit 0afaa9ff authored by Vincent Pelletier's avatar Vincent Pelletier

Make refreshWorklistCache safe to call even if the required scripts are not...

Make refreshWorklistCache safe to call even if the required scripts are not present. Also, it saves some acquisition lookups in the process.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@18520 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 8faa51ac
...@@ -546,59 +546,61 @@ def WorkflowTool_listActions(self, info=None, object=None): ...@@ -546,59 +546,61 @@ def WorkflowTool_listActions(self, info=None, object=None):
WorkflowTool.listActions = WorkflowTool_listActions WorkflowTool.listActions = WorkflowTool_listActions
def WorkflowTool_refreshWorklistCache(self): def WorkflowTool_refreshWorklistCache(self):
# XXX: Code below is duplicated from WorkflowTool_listActions Base_zInsertIntoWorklistTable = getattr(self, 'Base_zInsertIntoWorklistTable', None)
info = self._getOAI(None) if Base_zInsertIntoWorklistTable is not None:
worklist_dict = {} # XXX: Code below is duplicated from WorkflowTool_listActions
wf_ids = self.getWorkflowIds() info = self._getOAI(None)
for wf_id in wf_ids: worklist_dict = {}
wf = self.getWorkflowById(wf_id) wf_ids = self.getWorkflowIds()
if wf is not None: for wf_id in wf_ids:
a = wf.getWorklistVariableMatchDict(info) wf = self.getWorkflowById(wf_id)
if a is not None: if wf is not None:
worklist_dict[wf_id] = a a = wf.getWorklistVariableMatchDict(info)
# End of duplicated code if a is not None:
if len(worklist_dict): worklist_dict[wf_id] = a
self.Base_zCreateWorklistTable() # Create (or flush existing) table # End of duplicated code
portal_catalog = getToolByName(self, 'portal_catalog') if len(worklist_dict):
search_result = portal_catalog.unrestrictedSearchResults self.Base_zCreateWorklistTable() # Create (or flush existing) table
acceptable_key_dict = portal_catalog.getSQLCatalog().getColumnMap() portal_catalog = getToolByName(self, 'portal_catalog')
# XXX: those hardcoded lists should be grabbed from the table dynamicaly search_result = portal_catalog.unrestrictedSearchResults
# (and cached). acceptable_key_dict = portal_catalog.getSQLCatalog().getColumnMap()
table_column_id_set = ImmutableSet([ # XXX: those hardcoded lists should be grabbed from the table dynamicaly
COUNT_COLUMN_TITLE, 'security_uid', 'simulation_state', # (and cached).
'validation_state', 'portal_type', 'owner']) table_column_id_set = ImmutableSet([
security_column_id_list = ['security_uid', 'owner'] COUNT_COLUMN_TITLE, 'security_uid', 'simulation_state',
(worklist_list_grouped_by_condition, worklist_metadata) = \ 'validation_state', 'portal_type', 'owner'])
groupWorklistListByCondition( security_column_id_list = ['security_uid', 'owner']
worklist_dict=worklist_dict, (worklist_list_grouped_by_condition, worklist_metadata) = \
acceptable_key_dict=acceptable_key_dict) groupWorklistListByCondition(
assert COUNT_COLUMN_TITLE in table_column_id_set worklist_dict=worklist_dict,
for grouped_worklist_dict in worklist_list_grouped_by_condition: acceptable_key_dict=acceptable_key_dict)
# Generate the query for this worklist_list assert COUNT_COLUMN_TITLE in table_column_id_set
(total_criterion_id_list, query) = \ for grouped_worklist_dict in worklist_list_grouped_by_condition:
getWorklistListQuery(grouped_worklist_dict=grouped_worklist_dict) # Generate the query for this worklist_list
for criterion_id in total_criterion_id_list: (total_criterion_id_list, query) = \
assert criterion_id in table_column_id_set getWorklistListQuery(grouped_worklist_dict=grouped_worklist_dict)
for security_column_id in security_column_id_list: for criterion_id in total_criterion_id_list:
assert security_column_id not in total_criterion_id_list assert criterion_id in table_column_id_set
assert security_column_id in table_column_id_set for security_column_id in security_column_id_list:
total_criterion_id_list.append(security_column_id) assert security_column_id not in total_criterion_id_list
group_by_expression = ', '.join(total_criterion_id_list) assert security_column_id in table_column_id_set
assert COUNT_COLUMN_TITLE not in total_criterion_id_list total_criterion_id_list.append(security_column_id)
select_expression = 'count(*) as %s, %s' % (COUNT_COLUMN_TITLE, group_by_expression = ', '.join(total_criterion_id_list)
group_by_expression) assert COUNT_COLUMN_TITLE not in total_criterion_id_list
search_result_kw = {'select_expression': select_expression, select_expression = 'count(*) as %s, %s' % (COUNT_COLUMN_TITLE,
'group_by_expression': group_by_expression, group_by_expression)
'query': query} search_result_kw = {'select_expression': select_expression,
#LOG('refreshWorklistCache', WARNING, 'Using query: %s' % \ 'group_by_expression': group_by_expression,
# (search_result(src__=1, **search_result_kw), )) 'query': query}
catalog_brain_result = search_result(**search_result_kw) #LOG('refreshWorklistCache', WARNING, 'Using query: %s' % \
value_column_dict = dict([(x, []) for x in table_column_id_set]) # (search_result(src__=1, **search_result_kw), ))
for catalog_brain_line in catalog_brain_result.dictionaries(): catalog_brain_result = search_result(**search_result_kw)
for column_id, value in catalog_brain_line.iteritems(): value_column_dict = dict([(x, []) for x in table_column_id_set])
if column_id in value_column_dict: for catalog_brain_line in catalog_brain_result.dictionaries():
value_column_dict[column_id].append(value) for column_id, value in catalog_brain_line.iteritems():
if len(value_column_dict[COUNT_COLUMN_TITLE]): if column_id in value_column_dict:
self.Base_zInsertIntoWorklistTable(**value_column_dict) value_column_dict[column_id].append(value)
if len(value_column_dict[COUNT_COLUMN_TITLE]):
Base_zInsertIntoWorklistTable(**value_column_dict)
WorkflowTool.refreshWorklistCache = WorkflowTool_refreshWorklistCache WorkflowTool.refreshWorklistCache = WorkflowTool_refreshWorklistCache
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