was working, changes to displays
This commit is contained in:
@ -10,7 +10,7 @@ from sqlalchemy import func, desc
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from app import db
|
||||
from plugins.auth.models import User
|
||||
from plugins.auth.models import User, Invitation
|
||||
from plugins.plant.growlog.models import GrowLog
|
||||
from plugins.plant.models import Plant
|
||||
from plugins.media.models import Media
|
||||
@ -26,9 +26,9 @@ def dashboard():
|
||||
if current_user.role != 'admin':
|
||||
return "Access denied", 403
|
||||
|
||||
now = datetime.utcnow()
|
||||
week_ago = now - timedelta(days=7)
|
||||
month_ago= now - timedelta(days=30)
|
||||
now = datetime.utcnow()
|
||||
week_ago = now - timedelta(days=7)
|
||||
month_ago = now - timedelta(days=30)
|
||||
|
||||
# ─── Overview metrics ────────────────────────────────────────────── #
|
||||
|
||||
@ -51,7 +51,7 @@ def dashboard():
|
||||
# Sign‐ups last 30 days
|
||||
signup_dates = [(month_ago + timedelta(days=i)).date() for i in range(31)]
|
||||
signup_counts = [
|
||||
User.query.filter(func.date(User.created_at)==d).count()
|
||||
User.query.filter(func.date(User.created_at) == d).count()
|
||||
for d in signup_dates
|
||||
]
|
||||
chart_dates = [d.strftime('%Y-%m-%d') for d in signup_dates]
|
||||
@ -64,7 +64,7 @@ def dashboard():
|
||||
|
||||
# ─── Analytics aggregates ─────────────────────────────────────────── #
|
||||
|
||||
ev_q = AnalyticsEvent.query.filter(AnalyticsEvent.timestamp >= week_ago)
|
||||
ev_q = AnalyticsEvent.query.filter(AnalyticsEvent.timestamp >= week_ago)
|
||||
total_ev = ev_q.count() or 1
|
||||
error_ev = ev_q.filter(AnalyticsEvent.status_code >= 500).count()
|
||||
error_pct = round(error_ev / total_ev * 100, 1)
|
||||
@ -96,10 +96,14 @@ def dashboard():
|
||||
)
|
||||
for ua, cnt in ua_counts:
|
||||
b = 'Other'
|
||||
if 'Chrome' in ua: b = 'Chrome'
|
||||
elif 'Firefox' in ua: b = 'Firefox'
|
||||
elif 'Safari' in ua and 'Chrome' not in ua: b = 'Safari'
|
||||
elif 'Edge' in ua: b = 'Edge'
|
||||
if 'Chrome' in ua:
|
||||
b = 'Chrome'
|
||||
elif 'Firefox' in ua:
|
||||
b = 'Firefox'
|
||||
elif 'Safari' in ua and 'Chrome' not in ua:
|
||||
b = 'Safari'
|
||||
elif 'Edge' in ua:
|
||||
b = 'Edge'
|
||||
browsers[b] = browsers.get(b, 0) + cnt
|
||||
|
||||
referrers = dict(
|
||||
@ -116,16 +120,14 @@ def dashboard():
|
||||
|
||||
# ─── Stats metrics ────────────────────────────────────────────────── #
|
||||
|
||||
# Plant totals
|
||||
total_plants = Plant.query.count()
|
||||
total_plants = Plant.query.count()
|
||||
total_images = Media.query.count()
|
||||
active_plants = Plant.query.filter_by(is_active=True).count()
|
||||
active_plants = Plant.query.filter_by(is_active=True).count()
|
||||
|
||||
# Top 5 popular plant types
|
||||
popular_plants = db.session.query(
|
||||
Plant.plant_type,
|
||||
func.count(Plant.id).label('count')
|
||||
).filter(Plant.is_active==True) \
|
||||
).filter(Plant.is_active == True) \
|
||||
.group_by(Plant.plant_type) \
|
||||
.order_by(desc('count')) \
|
||||
.limit(5) \
|
||||
@ -340,7 +342,27 @@ def undelete_user(user_id):
|
||||
@bp.route('/orphaned-media')
|
||||
@login_required
|
||||
def orphaned_media_list():
|
||||
if not current_user.role == 'admin':
|
||||
abort(403)
|
||||
if current_user.role != 'admin':
|
||||
return "Access denied", 403
|
||||
items = Media.query.filter_by(status='orphaned').order_by(Media.orphaned_at.desc()).all()
|
||||
return render_template('admin/orphaned_media_list.html', items=items)
|
||||
return render_template('admin/orphaned_media_list.html', items=items)
|
||||
|
||||
|
||||
# ─── Invitation Management ──────────────────────────────────────────────── #
|
||||
|
||||
@bp.route('/invitations')
|
||||
@login_required
|
||||
def list_invitations():
|
||||
if current_user.role != 'admin':
|
||||
return "Access denied", 403
|
||||
|
||||
user_id = request.args.get('user_id', type=int)
|
||||
query = Invitation.query
|
||||
if user_id:
|
||||
query = query.filter(Invitation.created_by == user_id)
|
||||
invitations = query.order_by(Invitation.created_at.desc()).all()
|
||||
|
||||
return render_template(
|
||||
'admin/invitations/list.html',
|
||||
invitations=invitations
|
||||
)
|
||||
|
Reference in New Issue
Block a user