diff --git a/Website/main.py b/Website/main.py index 179d1e8..e4064f8 100644 --- a/Website/main.py +++ b/Website/main.py @@ -2466,62 +2466,35 @@ def my_instance_management(): @login_required def my_tutorials(): """Display tutorial videos for the logged-in user.""" - client = None - origin = request.url_root.rstrip("/") - try: - client, col = _get_collection("tutorials") - tutorials = list( - col.find( - {"published": True}, - { - "_id": 1, - "title": 1, - "description": 1, - "video_url": 1, - "thumbnail_url": 1, - "duration": 1, - "category": 1, - "created_at": 1, - }, - ).sort("created_at", -1) - ) - except PyMongoError: - flash("Tutorials konnten nicht geladen werden.", "error") - tutorials = [] - finally: - if client: - client.close() - - if not tutorials: - tutorials = [ - { - "_id": "1", - "title": "Erste Schritte mit Invario", - "description": "Lernen Sie die Grundlagen von Invario und wie Sie Ihre erste Instanz einrichten.", - "video_url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ", - "thumbnail_url": "/static/images/tutorial-thumb-1.jpg", - "duration": "12:34", - "category": "Anfänger" - }, - { - "_id": "2", - "title": "Inventarverwaltung", - "description": "Alles über die Verwaltung Ihres Inventars und der Ausleihvorgänge.", - "video_url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ", - "thumbnail_url": "/static/images/tutorial-thumb-2.jpg", - "duration": "18:45", - "category": "Funktionen" - }, - { - "_id": "3", - "title": "Admin-Funktionen", - "description": "Erweiterte Administratorfunktionen und Systemverwaltung.", - "video_url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ", - "thumbnail_url": "/static/images/tutorial-thumb-3.jpg", - "duration": "22:15", - "category": "Admin" - } - ] + tutorials = [ + { + "_id": "1", + "title": "Erste Schritte mit Invario", + "description": "Lernen Sie die Grundlagen von Invario und wie Sie Ihre erste Instanz einrichten.", + "video_url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ", + "thumbnail_url": "/static/images/tutorial-thumb-1.jpg", + "duration": "12:34", + "category": "Anfänger" + }, + { + "_id": "2", + "title": "Inventarverwaltung", + "description": "Alles über die Verwaltung Ihres Inventars und der Ausleihvorgänge.", + "video_url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ", + "thumbnail_url": "/static/images/tutorial-thumb-2.jpg", + "duration": "18:45", + "category": "Funktionen" + }, + { + "_id": "3", + "title": "Admin-Funktionen", + "description": "Erweiterte Administratorfunktionen und Systemverwaltung.", + "video_url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ", + "thumbnail_url": "/static/images/tutorial-thumb-3.jpg", + "duration": "22:15", + "category": "Admin" + } + ] normalized_tutorials = [] for item in tutorials: @@ -2534,116 +2507,6 @@ def my_tutorials(): return render_template("my_tutorials.html", tutorials=tutorials) -@app.route('/append_video', methods=['POST']) -@admin_required -def append_video(): - title = _sanitize_text(request.form.get("title") or "", 200) - description = _sanitize_text(request.form.get("description") or "", 500) - video_url = _sanitize_text(request.form.get("video_url") or "", 300) - thumbnail_url = _sanitize_text(request.form.get("thumbnail_url") or "", 300) - duration = _sanitize_text(request.form.get("duration") or "", 20) - category = _sanitize_text(request.form.get("category") or "", 50) - - if not title: - flash("Bitte einen Titel für das Tutorial eingeben.", "error") - return redirect(url_for("admin_blog")) - - if not video_url: - flash("Bitte eine Video-URL eingeben.", "error") - return redirect(url_for("admin_blog")) - - normalized_video_url = _normalize_tutorial_video_url(video_url, request.url_root.rstrip("/")) - - if not normalized_video_url: - flash( - "Ungültige Video-URL. Erlaubt sind YouTube-Links im Format watch?v=..., youtu.be/..., shorts/... oder embed/...", - "error", - ) - return redirect(url_for("admin_blog")) - - client = None - try: - client, col = _get_collection("tutorials") - col.insert_one( - { - "title": title, - "description": description, - "video_url": normalized_video_url, - "thumbnail_url": thumbnail_url, - "duration": duration, - "category": category, - "published": True, - "created_at": datetime.utcnow().isoformat(timespec="seconds") + "Z", - } - ) - flash("Tutorial-Video hinzugefügt.", "success") - except PyMongoError: - flash("Tutorial-Video konnte nicht hinzugefügt werden.", "error") - finally: - if client: - client.close() - - return redirect(url_for("admin_blog")) - - -@app.route('/admin/tutorials/upload', methods=['GET', 'POST']) -@admin_required -def admin_tutorial_upload(): - if request.method == 'POST': - title = _sanitize_text(request.form.get("title") or "", 200) - description = _sanitize_text(request.form.get("description") or "", 500) - duration = _sanitize_text(request.form.get("duration") or "", 20) - category = _sanitize_text(request.form.get("category") or "", 50) - thumbnail_url = _sanitize_text(request.form.get("thumbnail_url") or "", 300) - uploaded_file = request.files.get("video_file") - - if not title: - flash("Bitte einen Titel fuer das Tutorial eingeben.", "error") - return redirect(url_for("admin_tutorial_upload")) - - saved_video_path = _save_tutorial_video_file(uploaded_file, title) - if not saved_video_path: - flash("Bitte eine gueltige Videodatei hochladen (.mp4, .webm, .ogv, .ogg, .m4v).", "error") - return redirect(url_for("admin_tutorial_upload")) - - client = None - try: - client, col = _get_collection("tutorials") - col.insert_one( - { - "title": title, - "description": description, - "video_url": saved_video_path, - "thumbnail_url": thumbnail_url, - "duration": duration, - "category": category, - "published": True, - "created_at": datetime.utcnow().isoformat(timespec="seconds") + "Z", - "source": "upload", - } - ) - flash("Tutorial-Video wurde hochgeladen.", "success") - except PyMongoError: - flash("Tutorial-Video konnte nicht gespeichert werden.", "error") - finally: - if client: - client.close() - - return redirect(url_for("admin_tutorial_upload")) - - tutorials = [] - client = None - try: - client, col = _get_collection("tutorials") - tutorials = list(col.find({"source": "upload"}, {"_id": 1, "title": 1, "description": 1, "video_url": 1, "thumbnail_url": 1, "duration": 1, "category": 1, "created_at": 1}).sort("created_at", -1)) - except PyMongoError: - flash("Upload-Uebersicht konnte nicht geladen werden.", "error") - finally: - if client: - client.close() - - return render_template("admin_tutorial_upload.html", tutorials=tutorials) - @app.route('/chat', methods=['GET', 'POST']) @login_required diff --git a/Website/templates/admin_tutorial_upload.html b/Website/templates/admin_tutorial_upload.html deleted file mode 100644 index a008846..0000000 --- a/Website/templates/admin_tutorial_upload.html +++ /dev/null @@ -1,276 +0,0 @@ -{% extends "base.html" %} - -{% block title %}Admin | Tutorial-Upload{% endblock %} - -{% block head %} -{{ super() }} - -{% endblock %} - -{% block content %} -
-

Tutorial-Upload

-

Videodatei hochladen und sofort als Tutorial im Nutzerbereich bereitstellen.

- -
-
- - -
-
- - -
Erlaubte Formate: .mp4, .webm, .ogv, .ogg, .m4v
-
-
- - -
-
- - -
-
- - -
-
- - -
- -
- -
-
Vorschau erscheint nach Auswahl einer Videodatei.
- -
-
- -
-

Aktuelle Uploads

-

Neu hochgeladene Tutorials erscheinen hier und im Nutzerbereich.

- - {% if tutorials %} - {% for tutorial in tutorials %} -
-

{{ tutorial.title }} Upload

-
- {{ tutorial.category or 'Allgemein' }} | {{ tutorial.duration or 'ohne Dauer' }} | {{ tutorial.created_at[:10] }} -
-

{{ tutorial.description }}

- Video öffnen -
- {% endfor %} - {% else %} -

Noch keine hochgeladenen Tutorials vorhanden.

- {% endif %} -
- - -{% endblock %} diff --git a/Website/templates/base.html b/Website/templates/base.html index 8f84291..1f8d7fe 100644 --- a/Website/templates/base.html +++ b/Website/templates/base.html @@ -523,7 +523,6 @@ {% if session.get('is_admin') %} Rechnungsverwaltung Blog verwalten - Tutorial-Upload Admin-Chat Support-Center System-Tools @@ -551,7 +550,6 @@ Support-Center System-Tools Blog verwalten - Tutorial-Upload Schul-Instanzen