feat: update app logic and enhance base template rendering

This commit is contained in:
2025-05-03 19:19:53 +01:00
parent 7c742debdf
commit d5fababd49
3 changed files with 70 additions and 8 deletions

Binary file not shown.

74
app.py
View File

@@ -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/<int:category_id>')
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/<int:post_id>')
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)
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'}

View File

@@ -657,6 +657,10 @@
:class="darkMode ? 'text-gray-300 hover:text-white' : 'text-gray-600 hover:text-gray-900'">
Mindmap
</a>
<a href="{{ url_for('forum_index') }}" class="text-sm transition-all duration-200"
:class="darkMode ? 'text-gray-300 hover:text-white' : 'text-gray-600 hover:text-gray-900'">
Community
</a>
{% if current_user.is_authenticated %}
<a href="{{ url_for('profile') }}" class="text-sm transition-all duration-200"
:class="darkMode ? 'text-gray-300 hover:text-white' : 'text-gray-600 hover:text-gray-900'">