Fixed export

This commit is contained in:
Jonas Linter
2025-11-17 09:13:33 +01:00
parent 26c6d3ffbc
commit 9b82be9a6e

View File

@@ -7,6 +7,7 @@ import multiprocessing
import os
import traceback
import urllib.parse
import xml.dom.minidom
from collections import defaultdict
from datetime import date, datetime
from functools import partial
@@ -1323,8 +1324,17 @@ async def handle_xml_upload(
extension = Path(filename).suffix or ".xml"
log_filename = logs_dir / f"{base_filename}_{username}_{timestamp}{extension}"
# Save XML content to file
log_filename.write_text(xml_content, encoding="utf-8")
# Format and save XML content to file
try:
dom = xml.dom.minidom.parseString(xml_content)
pretty_xml = dom.toprettyxml(indent=" ")
# Remove extra blank lines that toprettyxml adds
pretty_xml = "\n".join([line for line in pretty_xml.split("\n") if line.strip()])
log_filename.write_text(pretty_xml, encoding="utf-8")
except Exception as e:
# If formatting fails, save the original content
_LOGGER.warning("Failed to format XML: %s. Saving unformatted.", str(e))
log_filename.write_text(xml_content, encoding="utf-8")
_LOGGER.info(
"XML file saved to %s by user %s (original: %s)",