Towards a working XML export

This commit is contained in:
Théophile Bastian 2018-02-26 15:58:30 +01:00
parent 67ad232533
commit e4ad8c7ce6

View file

@ -115,17 +115,25 @@ class History(models.Model):
runnner.run()
self.save()
def to_xml(self, xml_root):
def to_xml(self, xml_root=None):
''' Exports the current history to xml '''
standalone = False
if xml_root is None:
standalone = True
xml_root = ET.Element('root')
hist_node = ET.Element("history", attrib={
'start-ts': self.start_ts,
'played': 1 if self.played else 0,
'user': self.user.pk,
})
xml_root.append(hist_node)
for entry in self.historyentry_set:
for entry in self.historyentry_set.all():
entry.to_xml(hist_node)
if standalone:
return xml_root
@staticmethod
def from_xml(xml_root):
''' Loads an history from an XML file '''