Automatische Willkommensseite hinzugefügt
This commit is contained in:
96
app.py
96
app.py
@@ -1,7 +1,9 @@
|
||||
import os
|
||||
import json
|
||||
import socket
|
||||
import hashlib
|
||||
# Import welcome page functions
|
||||
import generate_welcome_page
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from flask import (
|
||||
@@ -16,6 +18,7 @@ from flask_login import (
|
||||
)
|
||||
from werkzeug.utils import secure_filename
|
||||
|
||||
|
||||
# -------------------------------------------------
|
||||
# Grundkonfiguration
|
||||
# -------------------------------------------------
|
||||
@@ -101,6 +104,87 @@ def logout():
|
||||
logout_user()
|
||||
return redirect("/login")
|
||||
|
||||
# -------------------------------------------------
|
||||
# Customer / Willkommensseite
|
||||
# -------------------------------------------------
|
||||
@app.route("/customer", methods=["GET", "POST"])
|
||||
@login_required
|
||||
def add_customer():
|
||||
"""Add new customer with logo search and welcome page"""
|
||||
error = None
|
||||
success = None
|
||||
logo_url = None
|
||||
|
||||
if request.method == "POST":
|
||||
customer_name = request.form.get("customer_name", "").strip()
|
||||
|
||||
if not customer_name:
|
||||
error = "Kundenname erforderlich"
|
||||
else:
|
||||
try:
|
||||
# Search for logo
|
||||
logo_url = generate_welcome_page.search_customer_logo(customer_name)
|
||||
|
||||
if not logo_url:
|
||||
error = "Logo konnte nicht gefunden werden"
|
||||
else:
|
||||
# Generate and save welcome page
|
||||
html_filename = generate_welcome_page.save_welcome_page(customer_name, logo_url)
|
||||
|
||||
if html_filename:
|
||||
# Add to lobby playlist
|
||||
if generate_welcome_page.add_customer_to_lobby_playlist(html_filename):
|
||||
success = f"✅ Kunde '{customer_name}' erfolgreich hinzugefügt!"
|
||||
else:
|
||||
error = "Fehler beim Hinzufügen zur Playliste"
|
||||
else:
|
||||
error = "Fehler beim Speichern der Willkommensseite"
|
||||
except ValueError as e:
|
||||
error = f"Konfigurationsfehler: {str(e)}"
|
||||
except Exception as e:
|
||||
error = f"Fehler: {str(e)}"
|
||||
|
||||
return render_template("customer.html", error=error, success=success, logo_url=logo_url)
|
||||
|
||||
@app.route("/api/customer", methods=["POST"])
|
||||
@login_required
|
||||
def api_add_customer():
|
||||
"""API endpoint for customer creation"""
|
||||
try:
|
||||
data = request.get_json()
|
||||
customer_name = data.get("customer_name", "").strip()
|
||||
|
||||
if not customer_name:
|
||||
return jsonify({"error": "Customer name required"}), 400
|
||||
|
||||
# Search for logo
|
||||
logo_url = generate_welcome_page.search_customer_logo(customer_name)
|
||||
|
||||
if not logo_url:
|
||||
return jsonify({"error": "Logo not found"}), 400
|
||||
|
||||
# Generate and save welcome page
|
||||
html_filename = generate_welcome_page.save_welcome_page(customer_name, logo_url)
|
||||
|
||||
if not html_filename:
|
||||
return jsonify({"error": "Failed to create welcome page"}), 500
|
||||
|
||||
# Add to lobby playlist
|
||||
if generate_welcome_page.add_customer_to_lobby_playlist(html_filename):
|
||||
return jsonify({
|
||||
"success": True,
|
||||
"message": f"Customer '{customer_name}' added successfully",
|
||||
"welcome_page": html_filename,
|
||||
"logo_url": logo_url
|
||||
}), 201
|
||||
else:
|
||||
return jsonify({"error": "Failed to add to playlist"}), 500
|
||||
|
||||
except ValueError as e:
|
||||
return jsonify({"error": str(e)}), 400
|
||||
except Exception as e:
|
||||
return jsonify({"error": str(e)}), 500
|
||||
|
||||
# -------------------------------------------------
|
||||
# Medien ausliefern
|
||||
# -------------------------------------------------
|
||||
@@ -136,6 +220,8 @@ def player(screen):
|
||||
return show_images
|
||||
if ext.endswith(".mp4"):
|
||||
return show_videos
|
||||
if ext.endswith((".html", ".htm")):
|
||||
return True
|
||||
return False
|
||||
|
||||
# ------------------------------
|
||||
@@ -266,7 +352,13 @@ def admin():
|
||||
continue
|
||||
|
||||
ext = os.path.splitext(item)[1].lower()
|
||||
ftype = "video" if ext == ".mp4" else "image"
|
||||
if ext == ".mp4":
|
||||
ftype = "video"
|
||||
if ext in (".jpg", ".jpeg", ".png"):
|
||||
ftype = "image"
|
||||
if ext == ".html":
|
||||
ftype = "html"
|
||||
|
||||
size = os.path.getsize(file_path) // 1024
|
||||
|
||||
files.append({
|
||||
|
||||
Reference in New Issue
Block a user