From 2127cc10cdfe94820d18ce1689ac04427271248f Mon Sep 17 00:00:00 2001 From: root Date: Tue, 24 Mar 2026 14:21:08 +0000 Subject: [PATCH] fix: robust HTML delivery for downloads section - Decoupled downloads container from main template to prevent static rendering errors - Forced HTMX polling to use html=1 parameter - Added server-side debug logging for request format detection - Fixed Jinja2 loop error by ensuring tasks are provided via HTMX --- app/routers/router_downloads.py | 5 +- templates/components/downloads_list.html | 64 ++++++++++++++---- templates/components/downloads_section.html | 73 +++------------------ 3 files changed, 66 insertions(+), 76 deletions(-) diff --git a/app/routers/router_downloads.py b/app/routers/router_downloads.py index e5c1779..c4ecfcb 100644 --- a/app/routers/router_downloads.py +++ b/app/routers/router_downloads.py @@ -27,14 +27,15 @@ async def get_downloads( """Get list of all download tasks. Returns HTML for HTMX.""" tasks = download_manager.get_all_tasks() - # Check for HTMX or explicit HTML request + # Force HTML if requested or via HTMX if html or request.headers.get("HX-Request"): - print(f"[DOWNLOADS] Returning HTML list for {len(tasks)} tasks") + print(f"[DOWNLOADS] HTMX Request detected. Returning HTML for {len(tasks)} tasks.") return templates.TemplateResponse( "components/downloads_list.html", {"request": request, "tasks": tasks} ) + print(f"[DOWNLOADS] API Request detected. Returning JSON.") return {"downloads": tasks} diff --git a/templates/components/downloads_list.html b/templates/components/downloads_list.html index c6bdce3..181a44b 100644 --- a/templates/components/downloads_list.html +++ b/templates/components/downloads_list.html @@ -1,8 +1,5 @@ -
- {% if tasks %} +{% if tasks %} +
{% for task in tasks %}
@@ -46,9 +43,54 @@
{% endfor %} - {% else %} -
-

Aucun téléchargement en cours

-
- {% endif %} -
+
+{% else %} +
+

Aucun téléchargement en cours

+
+{% endif %} + + diff --git a/templates/components/downloads_section.html b/templates/components/downloads_section.html index 3a232e1..c241076 100644 --- a/templates/components/downloads_section.html +++ b/templates/components/downloads_section.html @@ -5,77 +5,24 @@ -
- {% include "components/downloads_list.html" %} + +
+
+
Chargement des téléchargements... +