diff --git a/__pycache__/app.cpython-313.pyc b/__pycache__/app.cpython-313.pyc index c80ce46..2114fd3 100644 Binary files a/__pycache__/app.cpython-313.pyc and b/__pycache__/app.cpython-313.pyc differ diff --git a/app.py b/app.py index 1fccf4a..201bd84 100644 --- a/app.py +++ b/app.py @@ -1844,14 +1844,67 @@ def mindmap_page(): @app.route('/forum') @app.route('/Forum') @app.route('/community_forum') -def redirect_to_index(): - """Leitet alle Community/Forum-URLs zur Startseite um""" - return redirect(url_for('index')) +def forum_index(): + """Community-Forum-Startseite""" + # Kategorien und ihre Daten abrufen + categories = ForumCategory.query.all() + categories_data = [] + + for category in categories: + posts = ForumPost.query.filter_by(category_id=category.id, parent_id=None).count() + replies = ForumPost.query.filter(ForumPost.category_id == category.id, ForumPost.parent_id != None).count() + latest_post = ForumPost.query.filter_by(category_id=category.id).order_by(ForumPost.created_at.desc()).first() + + categories_data.append({ + 'category': category, + 'total_posts': posts, + 'total_replies': replies, + 'latest_post': latest_post + }) + + return render_template('community/index.html', categories_data=categories_data) -@app.route('/static/js/mindmap-init.js') -def serve_mindmap_init_js(): - """Bedient die Mindmap-Initialisierungsdatei.""" - return app.send_static_file('js/mindmap-init.js'), 200, {'Content-Type': 'application/javascript'} +@app.route('/community/category/') +def forum_category(category_id): + """Zeigt alle Posts einer bestimmten Kategorie an""" + category = ForumCategory.query.get_or_404(category_id) + posts = ForumPost.query.filter_by(category_id=category_id).order_by(ForumPost.created_at.desc()).all() + return render_template('community/category.html', category=category, posts=posts) + +@app.route('/community/post/') +def forum_post(post_id): + """Zeigt einen einzelnen Forumsbeitrag mit seinen Antworten an""" + post = ForumPost.query.get_or_404(post_id) + return render_template('community/post.html', post=post) + +@app.route('/community/new-post', methods=['GET', 'POST']) +@login_required +def forum_new_post(): + """Erstellen eines neuen Forumsbeitrags""" + if request.method == 'POST': + title = request.form.get('title') + content = request.form.get('content') + category_id = request.form.get('category') + + if not title or not content or not category_id: + flash('Bitte fülle alle erforderlichen Felder aus.', 'warning') + return redirect(url_for('forum_new_post')) + + post = ForumPost( + title=title, + content=content, + user_id=current_user.id, + category_id=category_id + ) + + db.session.add(post) + db.session.commit() + + flash('Dein Beitrag wurde erfolgreich erstellt!', 'success') + return redirect(url_for('forum_post', post_id=post.id)) + + categories = ForumCategory.query.all() + return render_template('community/new_post.html', categories=categories) # Datenbank-Update-Route (admin-geschützt) @app.route('/admin/update-database', methods=['GET', 'POST']) @@ -1875,4 +1928,9 @@ def admin_update_database(): message = f"Fehler: {str(e)}" success = False - return render_template('admin/update_database.html', message=message, success=success) \ No newline at end of file + return render_template('admin/update_database.html', message=message, success=success) + +@app.route('/static/js/mindmap-init.js') +def serve_mindmap_init_js(): + """Bedient die Mindmap-Initialisierungsdatei.""" + return app.send_static_file('js/mindmap-init.js'), 200, {'Content-Type': 'application/javascript'} \ No newline at end of file diff --git a/templates/base.html b/templates/base.html index 5c6e7e3..620064a 100644 --- a/templates/base.html +++ b/templates/base.html @@ -657,6 +657,10 @@ :class="darkMode ? 'text-gray-300 hover:text-white' : 'text-gray-600 hover:text-gray-900'"> Mindmap + + Community + {% if current_user.is_authenticated %}