From e4ad8c7ce6cf67ed0c4ddff79d575dda82c19d6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Bastian?= Date: Mon, 26 Feb 2018 15:58:30 +0100 Subject: [PATCH] Towards a working XML export --- histories/models.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/histories/models.py b/histories/models.py index 01a9f4d..45e6a7d 100644 --- a/histories/models.py +++ b/histories/models.py @@ -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 '''