Files
physicalCombinatorics/src/physcom_web/routes/admin.py

52 lines
1.5 KiB
Python

"""Admin panel routes."""
from __future__ import annotations
from flask import Blueprint, flash, redirect, render_template, url_for
from physcom.seed.transport_example import load_transport_seed
from physcom_web.app import get_repo
bp = Blueprint("admin", __name__, url_prefix="/admin")
@bp.route("/")
def admin_index():
repo = get_repo()
entities = repo.list_entities()
domains = repo.list_domains()
status_counts = repo.count_combinations_by_status()
runs = repo.list_pipeline_runs()
stats = {
"entities": len(entities),
"domains": len(domains),
"combinations": sum(status_counts.values()),
"pipeline_runs": len(runs),
}
return render_template("admin/index.html", stats=stats)
@bp.route("/reseed", methods=["POST"])
def reseed():
repo = get_repo()
counts = load_transport_seed(repo)
total = counts["platforms"] + counts["actuators"] + counts["energy_storages"]
flash(
f"Reseed complete — added {total} entities, {counts['domains']} domains.",
"success",
)
return redirect(url_for("admin.admin_index"))
@bp.route("/wipe-and-reseed", methods=["POST"])
def wipe_and_reseed():
repo = get_repo()
repo.clear_all()
counts = load_transport_seed(repo)
total = counts["platforms"] + counts["actuators"] + counts["energy_storages"]
flash(
f"Wiped all data and reseeded — {total} entities, {counts['domains']} domains.",
"success",
)
return redirect(url_for("admin.admin_index"))