Commit 8d30656b authored by Nicolas Delaby's avatar Nicolas Delaby

Add new parameter for replaceIdFromXML to specify id of replacement attribute


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@35817 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent de1cc27b
......@@ -625,21 +625,21 @@ class ERP5Conduit(XMLSyncUtilsMixin):
return self.convertXmlValue(subnode)
return None
def replaceIdFromXML(self, xml, new_id):
def replaceIdFromXML(self, xml, attribute_name, new_id, as_string=True):
"""
return a xml with id replace by a new id
"""
if xml is not None and new_id is not None:
if isinstance(xml, str):
xml = etree.XML(xml, parser=parser)
#copy of xml object for modification
xml_copy = deepcopy(xml)
if xml_copy.tag == self.xml_object_tag:
object_element = xml_copy
else:
object_element = xml_copy.xpath('//object')[0]
object_element.attrib['id'] = new_id
return etree.tostring(xml_copy)
#copy of xml object for modification
xml = deepcopy(xml)
object_element = xml.find('object')
del object_element.attrib['id']
object_element.attrib[attribute_name] = new_id
if as_string:
return etree.tostring(xml)
return xml
def getXMLFromObjectWithId(self, object, xml_mapping):
"""
......@@ -653,20 +653,20 @@ class ERP5Conduit(XMLSyncUtilsMixin):
xml = func()
return xml
def getXMLFromObjectWithGid(self, object, gid, xml_mapping=None):
def getXMLFromObjectWithGid(self, object, gid, xml_mapping, as_string=True):
"""
return the xml with Gid of Object
"""
xml_id = self.getXMLFromObjectWithId(object, xml_mapping)
xml_gid = self.replaceIdFromXML(xml_id, gid)
return xml_gid
xml_with_id = self.getXMLFromObjectWithId(object, xml_mapping)
return self.replaceIdFromXML(xml_with_id, 'gid', gid, as_string=as_string)
def getXMLFromObjectWithRid(self, object, rid, xml_mapping=None):
def getXMLFromObjectWithRid(self, object, rid, xml_mapping, as_string=True):
"""
return the xml with Rid of Object
"""
xml_id = self.getXMLFromObjectWithId(object, xml_mapping)
xml_rid = self.replaceIdFromXML(xml_id, rid)
xml_rid = self.replaceIdFromXML(xml_id, 'rid', rid, as_string=as_string)
return xml_rid
security.declareProtected(Permissions.AccessContentsInformation,'convertToXml')
......
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