initial: blog-app snapshot
This commit is contained in:
38
routes/watchdog.py
Normal file
38
routes/watchdog.py
Normal file
@@ -0,0 +1,38 @@
|
||||
"""Watchdog blueprint: /watchdog page + /watchdog/run trigger (CSRF-guarded)."""
|
||||
|
||||
import logging
|
||||
|
||||
from flask import Blueprint, flash, redirect, render_template, request, url_for
|
||||
|
||||
from extensions import get_db, get_watchdog_db
|
||||
from repositories import project_repo
|
||||
from security import validate_csrf
|
||||
from services import watchdog as watchdog_service
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
bp = Blueprint("watchdog", __name__)
|
||||
|
||||
|
||||
@bp.route("/watchdog")
|
||||
def page_watchdog():
|
||||
days = watchdog_service.parse_days(request.args.get("days"), default=7)
|
||||
reports = watchdog_service.load_watchdog_reports(get_watchdog_db(), days=days)
|
||||
starred = project_repo.get_starred_names(get_db())
|
||||
return render_template(
|
||||
"watchdog.html", reports=reports, days=days, starred=starred
|
||||
)
|
||||
|
||||
|
||||
@bp.route("/watchdog/run", methods=["POST"])
|
||||
def watchdog_run():
|
||||
validate_csrf()
|
||||
|
||||
ok, status, message = watchdog_service.trigger_watchdog_run()
|
||||
if ok:
|
||||
flash(message, "success")
|
||||
elif status in ("cooldown",):
|
||||
flash(message, "warning")
|
||||
else:
|
||||
flash(message, "danger")
|
||||
return redirect(url_for("watchdog.page_watchdog"))
|
||||
Reference in New Issue
Block a user