feat: badges imprimé (✅ copies) dans galeries admin+public; fix: timestamp_to_date dans print.html
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"""Routes du dashboard admin -- authentification requise."""
|
||||
|
||||
import logging
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
from fastapi import APIRouter, Request, Form
|
||||
@@ -141,6 +142,13 @@ async def admin_print(request: Request):
|
||||
queue = await printer_svc.get_queue()
|
||||
printers = await printer_svc.get_printers_status()
|
||||
|
||||
# Formate les dates pour le template Jinja2
|
||||
for q in queue:
|
||||
ts = q.get("requested_at")
|
||||
q["requested_at_str"] = (
|
||||
datetime.fromtimestamp(ts).strftime("%d/%m %H:%M") if ts else "—"
|
||||
)
|
||||
|
||||
return _templates.TemplateResponse(request, "admin/print.html", {
|
||||
"config": cfg,
|
||||
"queue": queue,
|
||||
|
||||
@@ -93,21 +93,25 @@ async def admin_get_photos(
|
||||
p["thumb_url"] = pb.thumbnail_url(pid)
|
||||
p["download_url"] = f"/api/gallery/download/{pid}"
|
||||
|
||||
# Croise avec la file d'impression en attente
|
||||
# Croise avec les stats d'impression (pending, printing, done)
|
||||
try:
|
||||
pending_map = await printer_svc.get_pending_by_photo_id()
|
||||
stats_map = await printer_svc.get_print_stats_by_photo_id()
|
||||
for p in page_photos:
|
||||
pid = p.get("photo_id", "")
|
||||
requests = pending_map.get(pid, [])
|
||||
p["print_requests"] = requests
|
||||
p["print_pending"] = len([r for r in requests if r["status"] == "pending"])
|
||||
p["print_printing"] = len([r for r in requests if r["status"] == "printing"])
|
||||
info = stats_map.get(pid, {})
|
||||
p["print_requests"] = info.get("requests", [])
|
||||
p["print_pending"] = info.get("pending", 0)
|
||||
p["print_printing"] = info.get("printing", 0)
|
||||
p["print_done"] = info.get("done", 0)
|
||||
p["print_done_copies"] = info.get("copies_done", 0)
|
||||
except Exception as e:
|
||||
logger.warning("Impossible de croiser avec print_queue: %s", e)
|
||||
for p in page_photos:
|
||||
p["print_requests"] = []
|
||||
p["print_pending"] = 0
|
||||
p["print_printing"] = 0
|
||||
p["print_requests"] = []
|
||||
p["print_pending"] = 0
|
||||
p["print_printing"] = 0
|
||||
p["print_done"] = 0
|
||||
p["print_done_copies"] = 0
|
||||
|
||||
return {
|
||||
"photos": page_photos,
|
||||
|
||||
@@ -74,6 +74,22 @@ async def api_gallery_photos(
|
||||
p["thumb_url"] = pb.thumbnail_url(pid)
|
||||
p["download_url"] = f"/api/gallery/download/{pid}"
|
||||
|
||||
# Ajoute les stats d'impression (copies réussies) pour les badges
|
||||
printer_svc = getattr(request.app.state, "printer_service", None)
|
||||
if printer_svc:
|
||||
try:
|
||||
stats_map = await printer_svc.get_print_stats_by_photo_id()
|
||||
for p in page_photos:
|
||||
pid = _get_id(p)
|
||||
info = stats_map.get(pid, {})
|
||||
p["print_done_copies"] = info.get("copies_done", 0)
|
||||
except Exception:
|
||||
for p in page_photos:
|
||||
p["print_done_copies"] = 0
|
||||
else:
|
||||
for p in page_photos:
|
||||
p["print_done_copies"] = 0
|
||||
|
||||
return {
|
||||
"photos": page_photos,
|
||||
"total": total,
|
||||
|
||||
Reference in New Issue
Block a user