feat: Erweiterung der Drucker-API und Verbesserung der Benutzeroberfläche durch Status-Checks. Neue Drucker sind standardmäßig aktiv, und ein zusätzlicher Endpunkt zum Hinzufügen von Druckern wurde implementiert. Die Drucker-Templates wurden aktualisiert, um verfügbare Drucker mit Status-Indikatoren anzuzeigen und Fallback-Mechanismen bei Ladefehlern zu integrieren.

This commit is contained in:
2025-05-27 11:05:10 +02:00
parent b289501d00
commit c39595382c
4 changed files with 309 additions and 14 deletions

View File

@@ -1975,12 +1975,21 @@ def create_printer():
mac_address=data.get("mac_address", ""),
plug_ip=data["plug_ip"],
status="offline",
active=True, # Neue Drucker sind standardmäßig aktiv
created_at=datetime.now()
)
db_session.add(new_printer)
db_session.commit()
# Sofortiger Status-Check für den neuen Drucker
ip_to_check = new_printer.plug_ip
if ip_to_check:
status, active = check_printer_status(ip_to_check)
new_printer.status = "available" if status == "online" else "offline"
new_printer.active = active
db_session.commit()
printer_data = {
"id": new_printer.id,
"name": new_printer.name,
@@ -1989,18 +1998,25 @@ def create_printer():
"mac_address": new_printer.mac_address,
"plug_ip": new_printer.plug_ip,
"status": new_printer.status,
"active": new_printer.active,
"created_at": new_printer.created_at.isoformat()
}
db_session.close()
printers_logger.info(f"Neuer Drucker '{new_printer.name}' erstellt von Admin {current_user.id}")
return jsonify({"printer": printer_data}), 201
return jsonify({"printer": printer_data, "message": "Drucker erfolgreich erstellt"}), 201
except Exception as e:
printers_logger.error(f"Fehler beim Erstellen eines Druckers: {str(e)}")
return jsonify({"error": "Interner Serverfehler"}), 500
@app.route("/api/printers/add", methods=["POST"])
@login_required
def add_printer():
"""Alternativer Endpunkt zum Hinzufügen von Druckern (für Frontend-Kompatibilität)."""
return create_printer()
@app.route("/api/printers/<int:printer_id>", methods=["PUT"])
@login_required
def update_printer(printer_id):