adding statistics page for admin
This commit is contained in:
29
web/app.py
29
web/app.py
@@ -21,6 +21,7 @@ from web.db import (
|
||||
set_user_keywords,
|
||||
get_all_regions,
|
||||
get_all_keywords,
|
||||
stats_overview,
|
||||
upsert_region,
|
||||
upsert_keyword,
|
||||
list_regions_full,
|
||||
@@ -487,6 +488,34 @@ def admin_taxonomy():
|
||||
return render_template('admin/taxonomy.html', title='Taxonomy', regions=regions, keywords=keywords)
|
||||
|
||||
|
||||
@app.route('/admin/stats', methods=['GET'])
|
||||
def admin_stats():
|
||||
if not require_admin():
|
||||
return redirect(url_for('login'))
|
||||
# Optional filters via query params
|
||||
keyword = request.args.get('keyword')
|
||||
region = request.args.get('region')
|
||||
try:
|
||||
stats = stats_overview()
|
||||
# For detailed jobs table, reuse get_all_jobs() and filter
|
||||
jobs = get_all_jobs()
|
||||
if keyword:
|
||||
jobs = [j for j in jobs if (j.get('keyword') or '') == keyword]
|
||||
if region:
|
||||
jobs = [j for j in jobs if (j.get('region') or '') == region]
|
||||
except Exception as e:
|
||||
flash(f'Error computing stats: {e}')
|
||||
stats = {
|
||||
'total_jobs': 0,
|
||||
'total_keywords': 0,
|
||||
'total_regions': 0,
|
||||
'jobs_per_keyword': [],
|
||||
'jobs_per_region': []
|
||||
}
|
||||
jobs = []
|
||||
return render_template('admin/stats.html', title='Statistics', stats=stats, jobs=jobs, regions=get_all_regions(), keywords=get_all_keywords())
|
||||
|
||||
|
||||
def init():
|
||||
"""Main function to run the Flask app."""
|
||||
# Ensure DB is initialized
|
||||
|
||||
Reference in New Issue
Block a user