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): ...@@ -625,21 +625,21 @@ class ERP5Conduit(XMLSyncUtilsMixin):
return self.convertXmlValue(subnode) return self.convertXmlValue(subnode)
return None 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 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):
if isinstance(xml, str): xml = etree.XML(xml, parser=parser)
xml = etree.XML(xml, parser=parser) else:
#copy of xml object for modification #copy of xml object for modification
xml_copy = deepcopy(xml) xml = deepcopy(xml)
if xml_copy.tag == self.xml_object_tag: object_element = xml.find('object')
object_element = xml_copy del object_element.attrib['id']
else: object_element.attrib[attribute_name] = new_id
object_element = xml_copy.xpath('//object')[0] if as_string:
object_element.attrib['id'] = new_id return etree.tostring(xml)
return etree.tostring(xml_copy) return xml
def getXMLFromObjectWithId(self, object, xml_mapping): def getXMLFromObjectWithId(self, object, xml_mapping):
""" """
...@@ -653,20 +653,20 @@ class ERP5Conduit(XMLSyncUtilsMixin): ...@@ -653,20 +653,20 @@ class ERP5Conduit(XMLSyncUtilsMixin):
xml = func() xml = func()
return xml 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 return the xml with Gid of Object
""" """
xml_id = self.getXMLFromObjectWithId(object, xml_mapping) xml_with_id = self.getXMLFromObjectWithId(object, xml_mapping)
xml_gid = self.replaceIdFromXML(xml_id, gid) return self.replaceIdFromXML(xml_with_id, 'gid', gid, as_string=as_string)
return xml_gid
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 return the xml with Rid of Object
""" """
xml_id = self.getXMLFromObjectWithId(object, xml_mapping) 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 return xml_rid
security.declareProtected(Permissions.AccessContentsInformation,'convertToXml') 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