"""Dashboard blueprint.""" from flask import Blueprint, render_template, session from ..helpers import _api, login_required dashboard_bp = Blueprint("dashboard", __name__) @dashboard_bp.get("/dashboard") @login_required def index(): token = session["access_token"] resp = _api("GET", "/users/me", token=token) user = resp.json() if resp.status_code == 200 else {} img_resp = _api("GET", "/images/", token=token) images = img_resp.json() if img_resp.status_code == 200 else [] gen_resp = _api("GET", "/generate/images", token=token) generated_images = gen_resp.json() if gen_resp.status_code == 200 else [] vid_resp = _api("GET", "/generate/videos", token=token) videos = vid_resp.json() if vid_resp.status_code == 200 else [] pending_videos = [v for v in videos if v.get( "status") not in ("completed", "failed")] completed_videos = [v for v in videos if v.get("status") == "completed"] return render_template("dashboard.html", user=user, images=images, generated_images=generated_images, pending_videos=pending_videos, completed_videos=completed_videos)