Fix quick stats to show dynamic data (Issue #7)
- Add calculate_quick_stats() to get real-time post counts - Calculate posts from last 24 hours instead of hardcoded value - Pass quick_stats to dashboard template - Update template to display dynamic posts_today count Fixes #7
This commit is contained in:
27
app.py
27
app.py
@@ -271,9 +271,32 @@ def check_first_user():
|
||||
pass
|
||||
|
||||
|
||||
def calculate_quick_stats():
|
||||
"""Calculate quick stats for dashboard"""
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
cached_posts, _ = _load_posts_cache()
|
||||
|
||||
# Calculate posts from today (last 24 hours)
|
||||
now = datetime.utcnow()
|
||||
today_start = now - timedelta(hours=24)
|
||||
today_timestamp = today_start.timestamp()
|
||||
|
||||
posts_today = sum(1 for post in cached_posts.values()
|
||||
if post.get('timestamp', 0) >= today_timestamp)
|
||||
|
||||
return {
|
||||
'posts_today': posts_today,
|
||||
'total_posts': len(cached_posts)
|
||||
}
|
||||
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
"""Serve the main feed page"""
|
||||
# Calculate stats
|
||||
quick_stats = calculate_quick_stats()
|
||||
|
||||
if current_user.is_authenticated:
|
||||
# Load user settings
|
||||
try:
|
||||
@@ -282,7 +305,7 @@ def index():
|
||||
logger.warning(f"Invalid user settings JSON for user {current_user.id}: {e}")
|
||||
user_settings = {}
|
||||
|
||||
return render_template('dashboard.html', user_settings=user_settings)
|
||||
return render_template('dashboard.html', user_settings=user_settings, quick_stats=quick_stats)
|
||||
else:
|
||||
# Check if anonymous access is allowed
|
||||
if app.config.get('ALLOW_ANONYMOUS_ACCESS', False):
|
||||
@@ -297,7 +320,7 @@ def index():
|
||||
'dark_patterns_opt_in': False
|
||||
}
|
||||
}
|
||||
return render_template('dashboard.html', user_settings=user_settings, anonymous=True)
|
||||
return render_template('dashboard.html', user_settings=user_settings, anonymous=True, quick_stats=quick_stats)
|
||||
else:
|
||||
# Redirect non-authenticated users to login
|
||||
return redirect(url_for('login'))
|
||||
|
||||
Reference in New Issue
Block a user