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