chore: Änderungen commited

This commit is contained in:
2025-05-10 23:10:31 +02:00
parent e7b3374c53
commit d1352286b7
2 changed files with 411 additions and 0 deletions

132
app.py
View File

@@ -2403,6 +2403,138 @@ def search_mindmap_nodes():
'results': []
}), 500
# Export/Import-Funktionen für Mindmaps
@app.route('/api/mindmap/<int:mindmap_id>/export', methods=['GET'])
@login_required
def export_mindmap(mindmap_id):
"""
Exportiert eine Mindmap im angegebenen Format.
Query-Parameter:
- format: Format der Exportdatei (json, xml, csv)
"""
try:
# Sicherheitscheck: Nur eigene Mindmaps oder Mindmaps, auf die der Benutzer Zugriff hat
mindmap = UserMindmap.query.get_or_404(mindmap_id)
# Prüfen, ob der Benutzer Zugriff auf diese Mindmap hat
can_access = mindmap.user_id == current_user.id
if not can_access and mindmap.is_private:
return jsonify({
'success': False,
'message': 'Keine Berechtigung für den Zugriff auf diese Mindmap'
}), 403
# Format aus Query-Parameter holen
export_format = request.args.get('format', 'json')
# Alle Knoten und ihre Positionen in dieser Mindmap holen
nodes_data = db.session.query(
MindMapNode, UserMindmapNode
).join(
UserMindmapNode, UserMindmapNode.node_id == MindMapNode.id
).filter(
UserMindmapNode.user_mindmap_id == mindmap_id
).all()
# Beziehungen zwischen Knoten holen
relationships = []
for node1, user_node1 in nodes_data:
for node2, user_node2 in nodes_data:
if node1.id != node2.id and node2 in node1.children:
relationships.append({
'source': node1.id,
'target': node2.id
})
# Exportdaten vorbereiten
export_data = {
'mindmap': {
'id': mindmap.id,
'name': mindmap.name,
'description': mindmap.description,
'created_at': mindmap.created_at.isoformat(),
'last_modified': mindmap.last_modified.isoformat()
},
'nodes': [{
'id': node.id,
'name': node.name,
'description': node.description or '',
'color_code': node.color_code or '#9F7AEA',
'x_position': user_node.x_position,
'y_position': user_node.y_position,
'scale': user_node.scale or 1.0
} for node, user_node in nodes_data],
'relationships': relationships
}
# Exportieren im angeforderten Format
if export_format == 'json':
response = app.response_class(
response=json.dumps(export_data, indent=2),
status=200,
mimetype='application/json'
)
response.headers["Content-Disposition"] = f"attachment; filename=mindmap_{mindmap_id}.json"
return response
elif export_format == 'xml':
import dicttoxml
xml_data = dicttoxml.dicttoxml(export_data)
response = app.response_class(
response=xml_data,
status=200,
mimetype='application/xml'
)
response.headers["Content-Disposition"] = f"attachment; filename=mindmap_{mindmap_id}.xml"
return response
elif export_format == 'csv':
import io
import csv
# CSV kann nicht die gesamte Struktur darstellen, daher nur die Knotenliste
output = io.StringIO()
writer = csv.writer(output)
# Schreibe Header
writer.writerow(['id', 'name', 'description', 'color_code', 'x_position', 'y_position', 'scale'])
# Schreibe Knotendaten
for node, user_node in nodes_data:
writer.writerow([
node.id,
node.name,
node.description or '',
node.color_code or '#9F7AEA',
user_node.x_position,
user_node.y_position,
user_node.scale or 1.0
])
output.seek(0)
response = app.response_class(
response=output.getvalue(),
status=200,
mimetype='text/csv'
)
response.headers["Content-Disposition"] = f"attachment; filename=mindmap_{mindmap_id}_nodes.csv"
return response
else:
return jsonify({
'success': False,
'message': f'Nicht unterstütztes Format: {export_format}'
}), 400
except Exception as e:
print(f"Fehler beim Exportieren der Mindmap: {str(e)}")
return jsonify({
'success': False,
'message': f'Fehler beim Exportieren: {str(e)}'
}), 500
# Automatische Datenbankinitialisierung - Aktualisiert für Flask 2.2+ Kompatibilität
def initialize_app():
"""Initialisierung der Anwendung"""