From d5fababd4957cedd608eceda46c66f406b968b53 Mon Sep 17 00:00:00 2001 From: marwin Date: Sat, 3 May 2025 19:19:53 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20update=20app=20logic=20and?= =?UTF-8?q?=20enhance=20base=20template=20rendering?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __pycache__/app.cpython-313.pyc | Bin 83152 -> 86756 bytes app.py | 74 ++++++++++++++++++++++++++++---- templates/base.html | 4 ++ 3 files changed, 70 insertions(+), 8 deletions(-) diff --git a/__pycache__/app.cpython-313.pyc b/__pycache__/app.cpython-313.pyc index c80ce464bfea45b7e3721dcb6a3edeb4cfac93bf..2114fd35f073e0f61d5e52fb094c56980be64931 100644 GIT binary patch delta 2831 zcmZuzeN0=|6~FiS8I0dEHnuU?#Nmkm@e3agDbB)2AxUYVA%w&)o}v(y8Zh8sOmqEc zz?x#xRt;#HQua2vQ?rSGwx%Vk$Ua0ibt)CoI!%@K-X7XR$m{Y4+ob+6fs(1x{@T6I z*r29Q^3ge*k9+PpzjH3~f^qxj#^R?Iiy7dr{#Dobx_7a-oO;Lp$oEl+D*(x#0T4d$ zfIyZ7=#jK!DLe8&2na|0l;CTjt~-Pe_w{+ZU+H!q9k4^f^0(Oin%KD?=Fj@&z76`# z7?hTpJZv|-c=AOn(x2CLv(MU{1+6^*VCV3c zhfD%&9RnbM-P=9n6a)QSRHLB<21}*gUWfE>-7K}v9F<->WugL5da_(a$BiKsPjCHs&UV@7;#Dr#|B@YN{ERq3l>sXLXp>F(MV#8 ziG{^TLe#ZM=Wy--e>6T4nQ0ssCu2O^vJPXTu_=Td21mkTn75%ed=7e(ke?9JPRLt? z+$H1}g#4J0d{PMDTo5EAMG^WoQP&Wz5OaJ1I#2kQ$R+f&joE|?_cBFiu_jS~O*#ET z7cslVjFLhO>e-@m*y02ZmiRAL&4Fh&V6W6ls+E#zt;DC4_|%ePbLTf*<*B*;ZRg>6 zQ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KqeP~G!%hk(VfC!lbfGXnv-f*ln0ar`My|X zyNx^J8ZKrgMz!g00vV-Mfs79v3{0%;l8urVxYaK+YJ6m3VoYcJ%*?=~`2o!Qz%{)( ph*3lFBa1L&G~@S7W(F?ltDI85ig|!0-q#mSR%3pw#+7Ws4gd(#aYq0E 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 %}