Commit bf8aa33c authored by Sebastien Robin's avatar Sebastien Robin

changed many things for the export of workflows


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@120 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent be6e219b
...@@ -1136,16 +1136,19 @@ class Base( CopyContainer, PortalContent, Base18, ActiveObject, ERP5PropertyMana ...@@ -1136,16 +1136,19 @@ class Base( CopyContainer, PortalContent, Base18, ActiveObject, ERP5PropertyMana
""" """
Generate an xml text corresponding to the content of this object Generate an xml text corresponding to the content of this object
""" """
xml = ''
if ident==0:
xml += '<erp5>'
LOG('asXML',0,'Working on: %s' % str(self.getPath())) LOG('asXML',0,'Working on: %s' % str(self.getPath()))
ident_string = '' # This is used in order to have the ident incremented ident_string = '' # This is used in order to have the ident incremented
# for every sub-object # for every sub-object
for i in range(0,ident): for i in range(0,ident):
ident_string += ' ' ident_string += ' '
xml = ident_string + '<object id=\"%s\" portal_type=\"%s\">\n' % (self.getId(),self.portal_type) xml += ident_string + '<object id=\"%s\" portal_type=\"%s\">\n' % (self.getId(),self.portal_type)
binary_data = self.getBinaryData() binary_data = self.getBinaryData()
# If we have an object containing some binary data # If we have an object containing some binary data
if binary_data is not None: if binary_data is not None and 0==1:
msg = MIMEBase('application','octet-stream') msg = MIMEBase('application','octet-stream')
msg.set_payload(binary_data.getvalue()) msg.set_payload(binary_data.getvalue())
Encoders.encode_base64(msg) Encoders.encode_base64(msg)
...@@ -1160,12 +1163,25 @@ class Base( CopyContainer, PortalContent, Base18, ActiveObject, ERP5PropertyMana ...@@ -1160,12 +1163,25 @@ class Base( CopyContainer, PortalContent, Base18, ActiveObject, ERP5PropertyMana
#if not prop.has_key('acquisition_base_category') \ #if not prop.has_key('acquisition_base_category') \
# and prop['id'] != 'categories_list' and prop['id'] != 'uid': # and prop['id'] != 'categories_list' and prop['id'] != 'uid':
if prop_id not in ('uid',): if prop_id not in ('uid',):
prop_type = 'type="' + self.getPropertyType(prop_id) + '"' prop_type = self.getPropertyType(prop_id)
xml_prop_type = 'type="' + prop_type + '"'
#try:
value = self.getProperty(prop_id) value = self.getProperty(prop_id)
#except AttributeError:
# value=None
xml += ident_string + ' <%s %s>' %(prop_id,prop_type) xml += ident_string + ' <%s %s>' %(prop_id,xml_prop_type)
if value is None: if value is None:
pass pass
elif prop_type in ('image','file','document'):
LOG('asXML',0,'value: %s' % str(value))
# This property is binary and should be converted with mime
msg = MIMEBase('application','octet-stream')
msg.set_payload(value.getvalue())
Encoders.encode_base64(msg)
ascii_data = msg.get_payload()
ascii_data = ascii_data.replace('\n','@@@\n')
xml+=ascii_data
elif self.getPropertyType(prop_id) in ['lines','tokens']: elif self.getPropertyType(prop_id) in ['lines','tokens']:
i = 1 i = 1
for line in value: for line in value:
...@@ -1173,31 +1189,35 @@ class Base( CopyContainer, PortalContent, Base18, ActiveObject, ERP5PropertyMana ...@@ -1173,31 +1189,35 @@ class Base( CopyContainer, PortalContent, Base18, ActiveObject, ERP5PropertyMana
if i<len(value): if i<len(value):
xml+='@@@' # XXX very bad hack, must find something better xml+='@@@' # XXX very bad hack, must find something better
i += 1 i += 1
elif self.getPropertyType(prop_id)=='text': elif self.getPropertyType(prop_id) in ('text','string'):
xml += str(value).replace('\n','@@@') xml += str(value).replace('\n','@@@')
else: else:
xml+= str(value) xml+= str(value)
xml += '</%s>\n' % prop_id xml += '</%s>\n' % prop_id
# We have to describe the workflow history # We have to describe the workflow history
""" if hasattr(self,'workflow_history'):
xml += ident_string + ' <workflow_history>\n' xml += ident_string + ' <workflow_history>\n'
workflow_list = self.workflow_history workflow_list = self.workflow_history
workflow_list_keys = workflow_list.keys() workflow_list_keys = workflow_list.keys()
workflow_list_keys.sort() workflow_list_keys.sort() # Make sure it is sorted
for workflow_id in workflow_list_keys: # Make sure it is sorted
xml += ident_string + ' <workflow id=\"%s\">\n' % workflow_id for workflow_id in workflow_list_keys:
for workflow_action in workflow_list[workflow_id]: # It is already sorted xml += ident_string + ' <workflow id=\"%s\">\n' % workflow_id
xml += ident_string + ' <workflow_action>\n' for workflow_action in workflow_list[workflow_id]: # It is already sorted
worfklow_variable_list = workflow_action.keys() xml += ident_string + ' <workflow_action>\n'
worfklow_variable_list.sort() worfklow_variable_list = workflow_action.keys()
for workflow_variable in worfklow_variable_list: # Make sure it is sorted worfklow_variable_list.sort()
xml += ident_string + ' <%s>%s' % (workflow_variable, for workflow_variable in worfklow_variable_list: # Make sure it is sorted
workflow_action[workflow_variable]) variable_type = "string" # Somewhat bad, should find a better way
xml += '</%s>\n' % workflow_variable if workflow_variable.find('time')>= 0:
xml += ident_string + ' </workflow_action>\n' variable_type = "date"
xml += ident_string + ' </workflow>\n' xml += ident_string + ' <%s type=\"%s\">%s' % (workflow_variable,
xml += ident_string + ' </workflow_history>\n' variable_type,workflow_action[workflow_variable])
""" xml += '</%s>\n' % workflow_variable
xml += ident_string + ' </workflow_action>\n'
xml += ident_string + ' </workflow>\n'
xml += ident_string + ' </workflow_history>\n'
# We should not describe security settings # We should not describe security settings
xml += ident_string + ' <security_info>\n' xml += ident_string + ' <security_info>\n'
...@@ -1211,13 +1231,14 @@ class Base( CopyContainer, PortalContent, Base18, ActiveObject, ERP5PropertyMana ...@@ -1211,13 +1231,14 @@ class Base( CopyContainer, PortalContent, Base18, ActiveObject, ERP5PropertyMana
# We have finished to generate the xml # We have finished to generate the xml
xml += ident_string + '</object>\n' xml += ident_string + '</object>\n'
if ident==0:
xml += '</erp5>'
# Now convert the string as unicode # Now convert the string as unicode
if type(xml) is type(u"a"): if type(xml) is type(u"a"):
xml_unicode = xml xml_unicode = xml
else: else:
xml_unicode = unicode(xml,encoding='iso-8859-1') xml_unicode = unicode(xml,encoding='iso-8859-1')
return xml_unicode.encode('utf-8') return xml_unicode.encode('utf-8')
# Optimized Menu System # Optimized Menu System
security.declarePublic('allowedContentTypes') security.declarePublic('allowedContentTypes')
def allowedContentTypes( self ): def allowedContentTypes( self ):
......
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