Commit 6174b17d authored by wenjie.zheng's avatar wenjie.zheng Committed by Sebastien Robin

ERP5/InteractionWorkflow.py: add showAsXML for interactionworkflow, variable, worklist, script.

parent 130eaefb
......@@ -32,6 +32,15 @@ from Products.ERP5Type.Workflow import addWorkflowFactory
from Products.CMFActivity.ActiveObject import ActiveObject
from Products.ERP5Type import Permissions
# show as xml library
from lxml import etree
from lxml.etree import Element, SubElement
from xml.sax.saxutils import escape, unescape
from xml_marshaller.xml_marshaller import Marshaller
MARSHALLER_NAMESPACE_URI = 'http://www.erp5.org/namespaces/marshaller'
marshaller = Marshaller(namespace_uri=MARSHALLER_NAMESPACE_URI,
as_tree=True).dumps
_MARKER = []
class InteractionWorkflowDefinition (DCWorkflowDefinition, ActiveObject):
......@@ -358,6 +367,138 @@ class InteractionWorkflowDefinition (DCWorkflowDefinition, ActiveObject):
return self.interactions.objectIds()
return None
def showAsXML(self, root=None):
if root is None:
root = Element('erp5')
return_as_object = False
# Define a list of __dict__.keys to show to users:
# It seems even in DC interaction workflow, creation guard hasn't been configured;
# so it is not used? thus I didn't show creation guard as xml here. (zwj)
interaction_workflow_prop_id_to_show = {'title':'string',
'description':'text', 'manager_bypass':'int'}
# workflow as XML, need to rename DC workflow's portal_type before comparison.
interaction_workflow = SubElement(root, 'interaction_workflow',
attrib=dict(reference=self.getReference(),
portal_type='Interaction Workflow'))
for prop_id in sorted(interaction_workflow_prop_id_to_show):
prop_value = self.__dict__[prop_id]
prop_type = interaction_workflow_prop_id_to_show[prop_id]
sub_object = SubElement(interaction_workflow, prop_id, attrib=dict(type=prop_type))
sub_object.text = str(prop_value)
# 1. Interaction as XML
# 2. Variable as XML
variable_reference_list = []
variable_id_list = sorted(self.variables.keys())
variable_prop_id_to_show = {'description':'text',
'default_expr':'string', 'for_catalog':'int', 'for_status':'int',
'update_always':'int'}
for vid in variable_id_list:
variable_reference_list.append(vid)
variables = SubElement(interaction_workflow, 'variables', attrib=dict(variable_list=str(variable_reference_list),
number_of_element=str(len(variable_reference_list))))
for vid in variable_id_list:
vdef = self.variables[vid]
variable = SubElement(variables, 'variable', attrib=dict(reference=vdef.getReference(),
portal_type='Variable'))
for property_id in sorted(variable_prop_id_to_show):
if property_id == 'default_expr':
expression = getattr(vdef, property_id, None)
if expression is not None:
property_value = expression.text
else:
property_value = ''
sub_object = SubElement(variable, property_id, attrib=dict(type='string'))
else:
property_value = vdef.__dict__[property_id]
property_type = variable_prop_id_to_show[property_id]
sub_object = SubElement(variable, property_id, attrib=dict(type=property_type))
sub_object.text = str(property_value)
# 3. Worklist as XML
worklist_reference_list = []
worklist_id_list = sorted(self.worklists.keys())
worklist_prop_id_to_show = {'description':'text',
'matched_portal_type_list':'text',
'matched_validation_state_list':'string',
'matched_simulation_state_list':'string', 'actbox_category':'string',
'actbox_name':'string', 'actbox_url':'string', 'actbox_icon':'string',
'guard':'object'}
for qid in worklist_id_list:
worklist_reference_list.append(qid)
worklists = SubElement(interaction_workflow, 'worklists', attrib=dict(worklist_list=str(worklist_reference_list),
number_of_element=str(len(worklist_reference_list))))
for qid in worklist_id_list:
qdef = self.worklists[qid]
worklist = SubElement(worklists, 'worklist', attrib=dict(reference=qdef.getReference(),
portal_type='Worklist'))
guard = SubElement(worklist, 'guard', attrib=dict(type='object'))
var_matches = qdef.__dict__['var_matches']
for property_id in sorted(worklist_prop_id_to_show):
if property_id == 'guard':
guard_obj = getattr(qdef, 'guard', None)
guard_prop_to_show = sorted({'roles':'guard configuration',
'groups':'guard configuration', 'permissions':'guard configuration',
'expr':'guard configuration'})
for prop_id in guard_prop_to_show:
if guard_obj is not None:
prop_value = getattr(guard_obj, prop_id, '')
else:
prop_value = ''
guard_config = SubElement(guard, prop_id, attrib=dict(type='guard configuration'))
if prop_value is None or prop_value == ():
prop_value = ''
guard_config.text = str(prop_value)
else:
if property_id == 'matched_portal_type_list':
var_id = 'portal_type'
property_value = var_matches.get(var_id)
elif property_id == 'matched_validation_state_list':
var_id = 'validation_state'
property_value = var_matches.get(var_id)
elif property_id == 'matched_simulation_state_list':
var_id = 'simulation_state'
property_value = var_matches.get(var_id)
else:
property_value = getattr(qdef, property_id)
if property_value is None:
property_value = ''
property_type = worklist_prop_id_to_show[property_id]
sub_object = SubElement(worklist, property_id, attrib=dict(type=property_type))
sub_object.text = str(property_value)
# 4. Script as XML
script_reference_list = []
script_id_list = sorted(self.scripts.keys())
script_prop_id_to_show = {'title':'string', 'body':'string', 'parameter_signature':'string'}
for sid in script_id_list:
script_reference_list.append(sid)
scripts = SubElement(interaction_workflow, 'scripts', attrib=dict(script_list=str(script_reference_list),
number_of_element=str(len(script_reference_list))))
for sid in script_id_list:
sdef = self.scripts[sid]
script = SubElement(scripts, 'script', attrib=dict(reference=sid,
portal_type='Workflow Script'))
for property_id in sorted(script_prop_id_to_show):
if property_id == 'body':
property_value = sdef.getBody()
elif property_id == 'parameter_signature':
property_value = sdef.getParams()
else:
property_value = getattr(sdef, property_id)
property_type = script_prop_id_to_show[property_id]
sub_object = SubElement(script, property_id, attrib=dict(type=property_type))
sub_object.text = str(property_value)
# return xml object
if return_as_object:
return root
return etree.tostring(root, encoding='utf-8',
xml_declaration=True, pretty_print=True)
Globals.InitializeClass(InteractionWorkflowDefinition)
addWorkflowFactory(InteractionWorkflowDefinition, id='interaction_workflow',
......
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