JSON statt txt
Dieser Commit ist enthalten in:
@ -1,11 +1,12 @@
|
||||
"""
|
||||
Profil-Export-Service für Account-Daten
|
||||
|
||||
Exportiert Account-Profile in verschiedene Formate (CSV, TXT, PDF).
|
||||
Exportiert Account-Profile in verschiedene Formate (CSV, JSON, PDF).
|
||||
"""
|
||||
|
||||
import os
|
||||
import csv
|
||||
import json
|
||||
import string
|
||||
import logging
|
||||
from io import BytesIO, StringIO
|
||||
@ -106,6 +107,50 @@ class ProfileExportService:
|
||||
logger.error(f"Fehler beim TXT-Export: {e}")
|
||||
raise
|
||||
|
||||
@staticmethod
|
||||
def export_to_json(account_data: Dict[str, Any]) -> bytes:
|
||||
"""
|
||||
Exportiert Account-Daten als JSON.
|
||||
|
||||
Args:
|
||||
account_data: Dictionary mit Account-Daten
|
||||
|
||||
Returns:
|
||||
JSON-Daten als bytes
|
||||
"""
|
||||
try:
|
||||
# JSON-Struktur aufbauen
|
||||
export_data = {
|
||||
"account": {
|
||||
field_key: account_data.get(field_key, "")
|
||||
for field_key in ProfileExportService.EXPORT_FIELDS.keys()
|
||||
},
|
||||
"export_info": {
|
||||
"exported_at": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
||||
"format_version": "1.0"
|
||||
}
|
||||
}
|
||||
|
||||
# None-Werte zu leeren Strings konvertieren
|
||||
for key, value in export_data["account"].items():
|
||||
if value is None:
|
||||
export_data["account"][key] = ""
|
||||
|
||||
# JSON mit Einrückung für Lesbarkeit
|
||||
json_content = json.dumps(
|
||||
export_data,
|
||||
ensure_ascii=False,
|
||||
indent=2,
|
||||
sort_keys=False
|
||||
)
|
||||
|
||||
logger.info("JSON-Export erfolgreich")
|
||||
return json_content.encode('utf-8')
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Fehler beim JSON-Export: {e}")
|
||||
raise
|
||||
|
||||
@staticmethod
|
||||
def export_to_pdf(account_data: Dict[str, Any]) -> bytes:
|
||||
"""
|
||||
@ -349,7 +394,7 @@ class ProfileExportService:
|
||||
|
||||
Args:
|
||||
account_data: Account-Daten zum Exportieren
|
||||
formats: Liste von Formaten ["csv", "txt", "pdf"]
|
||||
formats: Liste von Formaten ["csv", "json", "pdf"]
|
||||
password_protect: Wird ignoriert (für Rückwärtskompatibilität)
|
||||
|
||||
Returns:
|
||||
@ -366,9 +411,9 @@ class ProfileExportService:
|
||||
filename = ProfileExportService.generate_filename(account_data, "csv")
|
||||
files_dict[filename] = content
|
||||
|
||||
elif fmt == "txt":
|
||||
content = ProfileExportService.export_to_txt(account_data)
|
||||
filename = ProfileExportService.generate_filename(account_data, "txt")
|
||||
elif fmt == "json":
|
||||
content = ProfileExportService.export_to_json(account_data)
|
||||
filename = ProfileExportService.generate_filename(account_data, "json")
|
||||
files_dict[filename] = content
|
||||
|
||||
elif fmt == "pdf":
|
||||
|
||||
@ -138,9 +138,9 @@ class ProfileExportDialog(QDialog):
|
||||
}
|
||||
""")
|
||||
|
||||
self.txt_checkbox = QCheckBox("TXT")
|
||||
self.txt_checkbox.setChecked(False) # Standard: nicht aktiviert
|
||||
self.txt_checkbox.setStyleSheet(self.csv_checkbox.styleSheet())
|
||||
self.json_checkbox = QCheckBox("JSON")
|
||||
self.json_checkbox.setChecked(False) # Standard: nicht aktiviert
|
||||
self.json_checkbox.setStyleSheet(self.csv_checkbox.styleSheet())
|
||||
|
||||
self.pdf_checkbox = QCheckBox("PDF")
|
||||
self.pdf_checkbox.setChecked(False) # Standard: nicht aktiviert
|
||||
@ -148,7 +148,7 @@ class ProfileExportDialog(QDialog):
|
||||
|
||||
# Checkboxen zum Format-Layout hinzufügen
|
||||
format_layout.addWidget(self.csv_checkbox)
|
||||
format_layout.addWidget(self.txt_checkbox)
|
||||
format_layout.addWidget(self.json_checkbox)
|
||||
format_layout.addWidget(self.pdf_checkbox)
|
||||
|
||||
container_layout.addWidget(format_group)
|
||||
@ -226,8 +226,8 @@ class ProfileExportDialog(QDialog):
|
||||
selected_formats = []
|
||||
if self.csv_checkbox.isChecked():
|
||||
selected_formats.append("csv")
|
||||
if self.txt_checkbox.isChecked():
|
||||
selected_formats.append("txt")
|
||||
if self.json_checkbox.isChecked():
|
||||
selected_formats.append("json")
|
||||
if self.pdf_checkbox.isChecked():
|
||||
selected_formats.append("pdf")
|
||||
|
||||
@ -260,8 +260,8 @@ class ProfileExportDialog(QDialog):
|
||||
formats = []
|
||||
if self.csv_checkbox.isChecked():
|
||||
formats.append("csv")
|
||||
if self.txt_checkbox.isChecked():
|
||||
formats.append("txt")
|
||||
if self.json_checkbox.isChecked():
|
||||
formats.append("json")
|
||||
if self.pdf_checkbox.isChecked():
|
||||
formats.append("pdf")
|
||||
|
||||
|
||||
In neuem Issue referenzieren
Einen Benutzer sperren