Commit c42818c8 authored by iv's avatar iv

ERP5Workflow: change getStateValueDict to getStateValueList

change and rename method to return a dict
create new method to return state object for a given id
parent 31ec3de6
......@@ -26,8 +26,8 @@ def get_obj_and_reference_list(business_field):
wf = getattr(portal_workflow, wf_id)
if getattr(wf, "interactions", marker) is marker: # only way to make sure it is not an interaction workflow ?
result.append((wf, wf_id, 'workflow'))
for state_id, state in wf.getStateValueDict().items():
result.append((state, state_id, 'state'))
for state in wf.getStateValueList():
result.append((state, state.getReference(), 'state'))
for trans_id, trans in wf.getTransitionValueDict().items():
result.append((trans, trans_id, 'transition'))
if trans.trigger_type == 1 and trans.actbox_name: # 1 == TRIGGER_USER_ACTION
......
......@@ -65,7 +65,7 @@ if position_graph:\n
\n
def getWorkflowGraph(workflow):\n
graph = dict(node=dict(), edge=dict())\n
for state_id, state in workflow.getStateValueDict().iteritems():\n
for state in workflow.getStateValueList():\n
is_initial_state = state.getId() == workflow.getSourceId()\n
transition_id_list = []\n
graph[\'node\'][state.getId()] = dict(\n
......
......@@ -771,14 +771,12 @@ class ERP5Site(FolderMixIn, CMFSite, CacheCookieMixin):
Return a list of workflow states classified to a specific group.
"""
def getStateList(group):
state_dict = {}
state_list = []
for wf in self.portal_workflow.objectValues():
state_list = wf.getStateValueDict()
for state_id in state_list:
state = state_list[state_id]
for state in wf.getStateValueList():
if group in getattr(state, 'type_list', ()):
state_dict[state.getReference()] = None
return tuple(state_dict.keys())
state_list.append(state.getReference())
return tuple(state_list)
getStateList = CachingMethod(getStateList,
id=('_getPortalGroupedStateList', group),
......@@ -1298,15 +1296,13 @@ class ERP5Site(FolderMixIn, CMFSite, CacheCookieMixin):
Return all states which is related to simulation state workflow and state type
"""
def getStateList():
state_dict = {}
state_list = []
for wf in self.portal_workflow.objectValues():
if wf.getVariableValueDict() and wf.getStateVariable() == 'simulation_state':
state_list = wf.getStateValueDict()
for state_id in state_list:
state = state_list[state_id]
for state in wf.getStateValueList():
if getattr(state, 'type_list', None):
state_dict[state.getReference()] = None
return tuple(sorted(state_dict.keys()))
state_list.append(state.getReference())
return tuple(sorted_list)
getStateList = CachingMethod(getStateList,
id=('getPortalGroupedSimulationStateList'),
......
......@@ -32,22 +32,16 @@ def getActorName(actor):
# Get history
# XXX Compatibility
for history_name in ['history', 'building_history', 'installation_history']:
workflow_item_list = portal_workflow.getInfoFor(ob=context,
name='history', wf_id=workflow_id)
if workflow_item_list != []:
break
workflow = getattr(portal_workflow, workflow_id)
wf_state_var = workflow.getStateVariable()
wf_states = workflow.getStateValueDict()
wf_state_variable = workflow.getStateVariable()
wf_transitions = workflow.getTransitionValueDict()
next_serial = None
previous_obj = None
for workflow_item in workflow_item_list:
for workflow_item in portal_workflow.getInfoFor(ob=context, name='history',
wf_id=workflow_id)
# XXX removing str method generate a strange bug
o = newTempBase(portal_object, str(i))
current_object = newTempBase(portal_object, str(i))
i += 1
for key, value in workflow_item.items():
if key == 'serial' and not can_view_history:
......@@ -57,19 +51,20 @@ for workflow_item in workflow_item_list:
if key.startswith(compatibility_name):
# Display the workflow state in the state columns
key = key[len(compatibility_name):]
if key == wf_state_var:
if key == wf_state_variable:
state = workflow.getStateValueById(value)
# Store locally the id of state, usefull for merging action and transition
state_id = wf_states.get(value, marker) and wf_states[value].getReference()
o.setProperty('state_id', state_id)
state_id = marker if not state else value
current_object.setProperty('state_id', state_id)
key = 'state'
if display:
value = wf_states.get(value, marker) and wf_states[value].title
value = marker if not state else state.title
else:
value = state_id
if key == 'action':
# Store locally the id of action, usefull for merging action and transition
o.setProperty('action_id', value)
current_object.setProperty('action_id', value)
if value != '' and value is not None:
if value == "'edit'":
value = "edit"
......@@ -78,12 +73,14 @@ for workflow_item in workflow_item_list:
else:
value = wf_transitions.get(value, marker) and (wf_transitions[value].getReference() or wf_transitions[value].actbox_name) or value
if display:
if key == 'error_message' and same_type(value, ''):
value = context.Localizer.erp5_ui.gettext(value)
elif key == 'error_message' and same_type(value, []):
value = '. '.join(['%s' % x for x in value])
elif key == 'error_message':
value = '%s' % value
if key == 'error_message':
if same_type(value, ''):
value = context.Localizer.erp5_ui.gettext(value)
if same_type(value, []):
value = '. '.join(['%s' % x for x in value])
else:
value = '%s' % value
elif key == 'actor':
value = getActorName(value)
elif same_type(value, '') and key == 'state':
......@@ -92,13 +89,13 @@ for workflow_item in workflow_item_list:
value = getTranslationStringWithContext(context, value, 'transition', workflow_id)
if value is marker:
value = 'Does not exist'
o.setProperty(key, value)
current_object.setProperty(key, value)
# record current serial as "next serial" for the previous revision
if next_serial is not None and can_view_history:
previous_obj.setProperty('next_serial', o.serial)
next_serial = getattr(o, 'serial', None)
previous_obj = o
result.append(o)
previous_obj.setProperty('next_serial', current_object.serial)
next_serial = getattr(current_object, 'serial', None)
previous_obj = current_object
result.append(current_object)
return result
......@@ -11,7 +11,8 @@ state_dict = {}
item_list = []
for workflow_id in workflow_id_list:
workflow = getToolByName(context, 'portal_workflow')[workflow_id]
for state_id, state in workflow.getStateValueDict().items():
for state in workflow.getStateValueList():
state_id = state.getReference()
if state.title and state_id!='deleted':
if not state_dict.has_key(state_id):
# we hide states without titles
......
......@@ -183,25 +183,14 @@ for folder in context.portal_skins.objectValues(spec=('Folder',)):
for wf in context.portal_workflow.objectValues():
# Test workflow states
wf_states = wf.getStateValueDict()
wf_state_list = wf.getStateValueList()
message = ''
if wf_states not in (None, (), [], ''):
for state_id in wf_states.keys():
state = wf_states[state_id]
if wf_state_list:
for state in wf_state_list:
message += checkTitle('/'.join(['portal_workflow', wf.id, 'states', state.id]), 'title', state.title)
if message:
message_list.append(message)
# # Test workflow states
# wf_scripts = wf.scripts
# message = ''
# if wf_scripts not in (None, (), [], ''):
# for script in wf_scripts.objectValues():
# message += checkTitle('/'.join(['portal_workflow', wf.id, 'scripts', script.id]), 'id', script.id)
# if message:
# message_list.append(message)
# Test portal types
IGNORE_PORTAL_TYPE_SET = set(("Application Id Generator",
"Conceptual Id Generator", "DateTime Divergence Tester",
......
......@@ -32,15 +32,15 @@ for portal_type in portal_type:
workflow_set.add(workflow_id)
workflow = workflow_tool[workflow_id]
state_value_dict = workflow.getStateValueDict()
state_value_list = workflow.getStateValueList()
# skip interaction workflows
# or workflows with only one state (such as edit_workflow)
# or workflows using another state variable
if (state_value_dict is not None
if (state_value_list is not None
and len(workflow.getStateIdList()) > 1
and state_var in (None, workflow.getStateVariable()):
for state in state_value_dict.values():
for state in state_value_list:
if not state_id in state_set:
state_set.add(state_id)
result_list.append((str(translateString(state.title)), state_id))
......
......@@ -32,7 +32,8 @@ for portal_type in portal_type_list:
continue
state_var = wf.getStateVariable()
for state_id, state in wf.getStateValueDict().items():
for state in wf.getStateValueList():
state_id = state.getReference()
for lang in supported_languages:
key = (lang, portal_type.id, state_var, state_id)
if not translated_keys.has_key(key):
......
......@@ -12,8 +12,8 @@ for portal_type in context.allowedContentTypes():
portal_type_id = portal_type.getId()
portal_type_translated_title_dict[portal_type_id] = translateString(portal_type.getTitle())
for workflow in getWorkflowsFor(portal_type_id):
state_container = workflow.getStateValueDict()
if state_container is not None and len(state_container) > 1:
state_list = workflow.getStateValueList()
if state_list is not None and len(state_list) > 1:
state_var = workflow.getStateVariable()
if state_var is None:
state_var = 'state'
......@@ -22,8 +22,9 @@ for portal_type in context.allowedContentTypes():
type_state_variable_workflow_dict[(portal_type_id, state_var)] = workflow_id
state_count_dict = type_workflow_state_count_dict_dict.setdefault((portal_type_id, workflow_id), {})
translated_state_title_dict = workflow_translated_state_title_dict.setdefault(workflow_id, {})
for state_id, state in state_container.items():
for state in state_list:
# TODO: support workflow-specific translations
state_id = state.getReference()
translated_state_title_dict[state_id] = translateString(state.title)
state_count_dict[state_id] = 0
add(state_var)
......
......@@ -2742,7 +2742,7 @@ class TestInventory(TestOrderMixin, ERP5TypeTestCase):
Make sure that changing workflow state after delivered changes
records in stock table.
"""
delivered_state = self.portal.portal_workflow.inventory_workflow.getStateValueDict()['delivered']
delivered_state = self.portal.portal_workflow.inventory_workflow.getStateValueById('delivered')
delivered_state.addPossibleTransition('cancel')
self.commit()
......
......@@ -88,7 +88,7 @@ class WorkflowSecurityConfiguratorItem(ConfiguratorItemMixin, XMLObject):
state_list = table_dict['state']
for state_config in state_list:
state_id = state_config.pop('state')
state = workflow.getStateValueDict()[state_id]
state = workflow.getStateValueById(state_id)
# Clean the state matrix
for permission in permission_list:
state.setPermission(permission, 0, [])
......
......@@ -328,8 +328,9 @@ def getSearchDialog(self, REQUEST=None):
continue
workflow_set.add(state_var)
if workflow.getStateValueDict() is None or \
len(workflow.getStateValueDict()) <= 1:
state_list = workflow.getStateValueList()
if state_list is None or \
len(state_list) <= 1:
continue
field_id = 'your_%s' % state_var
......@@ -339,9 +340,8 @@ def getSearchDialog(self, REQUEST=None):
field.manage_edit_xmlrpc(dict(
form_id='Base_viewDialogFieldLibrary',
field_id='your_category_list'))
items = sorted([(translateString(x.title), x.id) for x_ref, x
in workflow.getStateValueDict().items()],
key=lambda x:str(x[0]))
items = sorted([(translateString(state.title), state.id) for state in state_list],
key=lambda state:str(state[0]))
field._surcharged_edit(
dict(title=translateString(workflow.title),
items=items,
......
......@@ -802,10 +802,10 @@ def DCWorkflowDefinition_getVariableIdList(self):
return []
def DCWorkflowDefinition_getStateVariable(self):
return self.state_var
def DCWorkflowDefinition_getStateValueDict(self):
def DCWorkflowDefinition_getStateValueList(self):
if self.states is not None:
return self.states
return {}
return self.states.values()
return []
def DCWorkflowDefinition_getStateIdList(self):
if self.states is not None:
return self.states.objectIds()
......@@ -1085,7 +1085,7 @@ DCWorkflowDefinition.notifyWorkflowMethod = DCWorkflowDefinition_notifyWorkflowM
DCWorkflowDefinition.notifyBefore = DCWorkflowDefinition_notifyBefore
DCWorkflowDefinition.notifySuccess = DCWorkflowDefinition_notifySuccess
DCWorkflowDefinition.getVariableValueDict = DCWorkflowDefinition_getVariableValueDict
DCWorkflowDefinition.getStateValueDict = DCWorkflowDefinition_getStateValueDict
DCWorkflowDefinition.getStateValueList = DCWorkflowDefinition_getStateValueList
DCWorkflowDefinition.getTransitionValueDict = DCWorkflowDefinition_getTransitionValueDict
DCWorkflowDefinition.getWorklistValueDict = DCWorkflowDefinition_getWorklistValueDict
DCWorkflowDefinition.getScriptValueDict = DCWorkflowDefinition_getScriptValueDict
......
......@@ -970,7 +970,7 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor):
self.getWorkflowTool().getWorkflowValueListFor('Person'))
self.assertEqual('validation_state', wf.getStateVariable())
initial_state = wf.getSourceValue()
other_state = wf.getStateValueDict()['validated']
other_state = wf.getStateValueById(['validated'])
self.assertTrue(hasattr(person, 'getValidationState'))
self.assertTrue(hasattr(person, 'getValidationStateTitle'))
......
......@@ -367,8 +367,11 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), Workflow):
return 1
return 0
def getStateValueDict(self):
return {}
def getStateValueById(self, reference):
return None
def getStateValueList(self):
return []
def showAsXML(self, root=None):
if root is None:
......
......@@ -490,15 +490,20 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
id_list.append(ob.getReference())
return id_list
def getStateValueDict(self):
state_dict = {}
for sdef in self.objectValues(portal_type="State"):
state_dict[sdef.getReference()] = sdef
return state_dict
def getStateValueById(self, stated_id):
# TODO: returns state value for given id or None
try:
state_value = self._getOb('state_' + stated_id)
except AttributeError:
state_value = None
return state_value
def getStateValueList(self):
return self.objectValues(portal_type="State")
def getStateIdList(self):
id_list = []
for ob in self.objectValues(portal_type="State"):
for ob in self.ValueobjectValues(portal_type="State"):
id_list.append(ob.getReference())
return id_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