Towards a working XML export
This commit is contained in:
parent
67ad232533
commit
e4ad8c7ce6
1 changed files with 10 additions and 2 deletions
|
@ -115,17 +115,25 @@ class History(models.Model):
|
||||||
runnner.run()
|
runnner.run()
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
def to_xml(self, xml_root):
|
def to_xml(self, xml_root=None):
|
||||||
''' Exports the current history to xml '''
|
''' 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={
|
hist_node = ET.Element("history", attrib={
|
||||||
'start-ts': self.start_ts,
|
'start-ts': self.start_ts,
|
||||||
'played': 1 if self.played else 0,
|
'played': 1 if self.played else 0,
|
||||||
'user': self.user.pk,
|
'user': self.user.pk,
|
||||||
})
|
})
|
||||||
xml_root.append(hist_node)
|
xml_root.append(hist_node)
|
||||||
for entry in self.historyentry_set:
|
for entry in self.historyentry_set.all():
|
||||||
entry.to_xml(hist_node)
|
entry.to_xml(hist_node)
|
||||||
|
|
||||||
|
if standalone:
|
||||||
|
return xml_root
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_xml(xml_root):
|
def from_xml(xml_root):
|
||||||
''' Loads an history from an XML file '''
|
''' Loads an history from an XML file '''
|
||||||
|
|
Loading…
Reference in a new issue