29 lines
872 B
Python
29 lines
872 B
Python
from __future__ import annotations
|
|
|
|
from flask import Blueprint, redirect, render_template, url_for
|
|
from flask_login import current_user, login_required
|
|
|
|
from app.models import Account, AttendanceEvent, Person
|
|
|
|
bp = Blueprint("main", __name__)
|
|
|
|
|
|
@bp.get("/")
|
|
def index():
|
|
if current_user.is_authenticated:
|
|
return redirect(url_for("main.dashboard"))
|
|
return render_template("welcome.html")
|
|
|
|
|
|
@bp.get("/dashboard")
|
|
@login_required
|
|
def dashboard():
|
|
stats = {
|
|
"people": Person.query.count(),
|
|
"active_people": Person.query.filter_by(active=True).count(),
|
|
"events": AttendanceEvent.query.count(),
|
|
"accounts": Account.query.count(),
|
|
}
|
|
latest_events = AttendanceEvent.query.order_by(AttendanceEvent.occurred_at.desc()).limit(8).all()
|
|
return render_template("dashboard.html", stats=stats, latest_events=latest_events)
|