Commit 6edaa9b6 authored by Vincent Pelletier's avatar Vincent Pelletier

Rework Folder_generateWorkflowReport

Add support for honoring user selection, and related option (enabled by default).
Query catalog only once.
Do not use custom ZSQLMethod.
parent e0c95b82
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="SQL" module="Products.ZSQLMethods.SQL"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_col</string> </key>
<value>
<list>
<dictionary>
<item>
<key> <string>name</string> </key>
<value> <string>validation_state</string> </value>
</item>
<item>
<key> <string>null</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>type</string> </key>
<value> <string>t</string> </value>
</item>
<item>
<key> <string>width</string> </key>
<value> <int>5</int> </value>
</item>
</dictionary>
<dictionary>
<item>
<key> <string>name</string> </key>
<value> <string>count(*)</string> </value>
</item>
<item>
<key> <string>null</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>type</string> </key>
<value> <string>l</string> </value>
</item>
<item>
<key> <string>width</string> </key>
<value> <int>2</int> </value>
</item>
</dictionary>
</list>
</value>
</item>
<item>
<key> <string>allow_simple_one_argument_traversal</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>arguments_src</string> </key>
<value> <string>portal_type=""\r\n
state_name=""</string> </value>
</item>
<item>
<key> <string>cache_time_</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>class_file_</string> </key>
<value> <string>ZSQLCatalog.zsqlbrain</string> </value>
</item>
<item>
<key> <string>class_name_</string> </key>
<value> <string>ZSQLBrain</string> </value>
</item>
<item>
<key> <string>connection_hook</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>connection_id</string> </key>
<value> <string>erp5_sql_connection</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_zCountByWorkflowState</string> </value>
</item>
<item>
<key> <string>max_cache_</string> </key>
<value> <int>100</int> </value>
</item>
<item>
<key> <string>max_rows_</string> </key>
<value> <int>1000</int> </value>
</item>
<item>
<key> <string>src</string> </key>
<value> <string encoding="cdata"><![CDATA[
SELECT catalog.<dtml-var expr="state_name">, count(*)\n
FROM catalog\n
\n
WHERE\n
\n
catalog.portal_type = "<dtml-var expr="portal_type">"\n
\n
GROUP BY catalog.<dtml-var expr="state_name">\n
\n
]]></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -50,84 +50,81 @@ ...@@ -50,84 +50,81 @@
</item> </item>
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string>listbox = []\n <value> <string encoding="cdata"><![CDATA[
result_dict = {}\n
translate_state_dict = {}\n portal = context.getPortalObject()\n
state_dict={}\n translateString = portal.Base_translateString\n
portal_type_dict={}\n getWorkflowsFor = portal.portal_workflow.getWorkflowsFor\n
workflow_dict={}\n state_variable_set = set()\n
portal_workflow = context.portal_workflow\n add = state_variable_set.add\n
content_type_list = context.allowedContentTypes()\n type_state_variable_workflow_dict = {}\n
content_type_list.sort()\n type_workflow_state_count_dict_dict = {}\n
\n workflow_translated_title_dict = {}\n
translateString = context.Base_translateString\n workflow_translated_state_title_dict = {}\n
\n portal_type_translated_title_dict = {}\n
workflow_tool = context.portal_workflow\n for portal_type in context.allowedContentTypes():\n
for portal_type in content_type_list:\n
portal_type_id = portal_type.getId()\n portal_type_id = portal_type.getId()\n
workflow_list = workflow_tool.getWorkflowsFor(portal_type_id)\n portal_type_translated_title_dict[portal_type_id] = translateString(portal_type.getTitle())\n
# Retrieve the workflows by portal_type\n for workflow in getWorkflowsFor(portal_type_id):\n
for workflow in workflow_list:\n state_container = getattr(workflow, \'states\', None)\n
# not \'edit_workflow\' because state variable is not in catalog\n if state_container is not None and len(state_container) > 1:\n
if getattr(workflow, \'states\', None) is not None and \\\n
workflow.getId() != \'edit_workflow\':\n
#retrieve state_var to search in the catalog the states use by the\n
#workflow\n
state_var = workflow.state_var\n state_var = workflow.state_var\n
result_list = context.Base_zCountByWorkflowState(portal_type=portal_type_id,\n workflow_id = workflow.getId()\n
state_name=state_var)\n workflow_translated_title_dict[workflow_id] = translateString(workflow.title)\n
if not ((len(result_list) == 1) and (result_list[0][0] is None)):\n type_state_variable_workflow_dict[(portal_type_id, state_var)] = workflow_id\n
for result in result_list:\n state_count_dict = type_workflow_state_count_dict_dict.setdefault((portal_type_id, workflow_id), {})\n
portal_type_dict = result_dict.get(portal_type_id,{})\n translated_state_title_dict = workflow_translated_state_title_dict.setdefault(workflow_id, {})\n
workflow_dict = portal_type_dict.get(workflow.title,{})\n for state in state_container.objectValues():\n
workflow_dict.update({result[0]:result[1]})\n state_id = state.getId()\n
portal_type_dict.update({workflow.title:workflow_dict})\n # TODO: support workflow-specific translations\n
result_dict.update({portal_type_id:portal_type_dict})\n translated_state_title_dict[state_id] = translateString(state.title)\n
# store the title states for the translation\n state_count_dict[state_id] = 0\n
if not translate_state_dict.has_key(result[0]):\n add(state_var)\n
state_title = getattr(workflow.states, result[0]).title_or_id()\n column_list = [\'portal_type\'] + list(state_variable_set)\n
translate_state_dict[result[0]] = state_title\n COUNT = \'count(*)\'\n
\n if use_selection:\n
#Display the result\n selection_kw = portal.portal_selections.getSelectionParamsFor(selection_name).copy()\n
state_list_dict = {}\n selection_kw.pop(\'limit\', None)\n
portal_type_list = result_dict.keys()\n query = portal.portal_catalog.getSQLCatalog().buildQuery(selection_kw)\n
portal_type_list.sort()\n else:\n
for portal_type in portal_type_list:\n query = None\n
workflow_list = result_dict[portal_type].keys()\n for line in context.searchFolder(group_by=column_list, select_list=[COUNT] + column_list, query=query):\n
for workflow_title in workflow_list:\n portal_type = line.portal_type\n
listbox.append({\'translated_portal_type\': \'%s - %s\' %\\\n count = getattr(line, COUNT)\n
(translateString(portal_type), translateString(workflow_title)),\n for state_variable in state_variable_set:\n
workflow = type_state_variable_workflow_dict.get((line.portal_type, state_variable))\n
state = getattr(line, state_variable)\n
if workflow is None:\n
assert not state, (portal_type, state_variable, state)\n
continue\n
state_count_dict = type_workflow_state_count_dict_dict[(portal_type, workflow)]\n
state_count_dict[state] = count + state_count_dict[state]\n
listbox = []\n
append = listbox.append\n
for (portal_type, workflow), state_count_dict in sorted(type_workflow_state_count_dict_dict.iteritems(), key=lambda x: x[0]):\n
if sum(state_count_dict.values()):\n
append({\n
\'translated_portal_type\': \'%s - %s\' % (portal_type_translated_title_dict[portal_type], workflow_translated_title_dict[workflow]),\n
\'state\' : \'\',\n \'state\' : \'\',\n
\'count\' : \'\'})\n \'count\' : \'\',\n
state_list = result_dict[portal_type][workflow_title].keys()\n })\n
state_list.sort()\n translated_state_title_dict = workflow_translated_state_title_dict[workflow]\n
for state in state_list:\n for state, count in sorted(state_count_dict.iteritems(), key=lambda x: x[0]):\n
result_count = result_dict[portal_type][workflow_title][state]\n if count:\n
count = state_list_dict.get(state, 0) + result_count\n append({\n
# account the number of items by state\n \'translated_portal_type\': \'\',\n
state_list_dict.update({state:count})\n \'state\': translated_state_title_dict[state],\n
listbox.append({\'translated_portal_type\': \'\',\n \'count\': count,\n
\'state\' : translateString(translate_state_dict[state]),\n })\n
\'count\' : result_count})\n portal.Base_updateDialogForm(listbox=listbox, empty_line_number=0)\n
\n
#Display the total by state\n
listbox.append({\'translated_portal_type\': translateString(\'All\'),\n
\'state\' : \'\',\n
\'count\' : \'\'})\n
state_list = state_list_dict.keys()\n
state_list.sort()\n
for state in state_list:\n
listbox.append({\'translated_portal_type\': \'\',\n
\'state\' : translateString(translate_state_dict[state]),\n
\'count\' : state_list_dict[state]})\n
\n
context.Base_updateDialogForm(listbox=listbox, empty_line_number=0)\n
return context.Folder_viewWorkflowReport()\n return context.Folder_viewWorkflowReport()\n
</string> </value>
]]></string> </value>
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string></string> </value> <value> <string>use_selection, selection_name</string> </value>
</item> </item>
<item> <item>
<key> <string>_proxy_roles</string> </key> <key> <string>_proxy_roles</string> </key>
......
...@@ -73,6 +73,7 @@ ...@@ -73,6 +73,7 @@
<list> <list>
<string>your_format</string> <string>your_format</string>
<string>your_portal_skin</string> <string>your_portal_skin</string>
<string>your_use_selection</string>
</list> </list>
</value> </value>
</item> </item>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ProxyField" module="Products.ERP5Form.ProxyField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>delegated_list</string> </key>
<value>
<list>
<string>default</string>
<string>title</string>
</list>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>your_use_selection</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
<value>
<dictionary>
<item>
<key> <string>external_validator_failed</string> </key>
<value> <string>The input failed the external validator.</string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>overrides</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>default</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_checkbox</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Base_viewFieldLibrary</string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string>Click to edit the target</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Use Current Selection</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
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