From 2ac263e80a719af2c8d3f9379ba738ba9f62290d Mon Sep 17 00:00:00 2001 From: Khalid MOUTAOUAKIL Date: Mon, 6 Apr 2026 17:35:38 +0200 Subject: [PATCH] Tri colonnes hostname, uptime, reboot (asc/desc) avec indicateur fleche Co-Authored-By: Claude Opus 4.6 (1M context) --- app/routers/audit_full.py | 24 ++++++++++++++++++++++++ app/templates/audit_full_list.html | 6 +++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/app/routers/audit_full.py b/app/routers/audit_full.py index a71c262..58cc347 100644 --- a/app/routers/audit_full.py +++ b/app/routers/audit_full.py @@ -153,6 +153,29 @@ async def audit_full_list(request: Request, db=Depends(get_db)): q = search.lower() audits = [a for a in audits if q in a.hostname.lower()] + # Tri + sort = request.query_params.get("sort", "hostname") + sort_dir = request.query_params.get("dir", "asc") + if sort == "hostname": + audits.sort(key=lambda a: a.hostname.lower(), reverse=(sort_dir == "desc")) + elif sort == "uptime": + def uptime_days(a): + u = a.uptime or "" + d = 0 + import re as _re + m = _re.search(r"(\d+) year", u) + if m: d += int(m.group(1)) * 365 + m = _re.search(r"(\d+) month", u) + if m: d += int(m.group(1)) * 30 + m = _re.search(r"(\d+) week", u) + if m: d += int(m.group(1)) * 7 + m = _re.search(r"(\d+) day", u) + if m: d += int(m.group(1)) + return d + audits.sort(key=uptime_days, reverse=(sort_dir == "desc")) + elif sort == "reboot": + audits.sort(key=lambda a: (1 if a.reboot_required else 0), reverse=(sort_dir == "desc")) + # Pagination total_filtered = len(audits) total_pages = max(1, (total_filtered + per_page - 1) // per_page) @@ -164,6 +187,7 @@ async def audit_full_list(request: Request, db=Depends(get_db)): "app_name": APP_NAME, "audits": audits_page, "kpis": kpis, "filter": filtre, "search": search, "domain": domain, "all_domains": all_domains, "all_zones": all_zones, + "sort": sort, "sort_dir": sort_dir, "page": page, "total_pages": total_pages, "total_filtered": total_filtered, "msg": request.query_params.get("msg"), }) diff --git a/app/templates/audit_full_list.html b/app/templates/audit_full_list.html index ac2f476..2b6d5cf 100644 --- a/app/templates/audit_full_list.html +++ b/app/templates/audit_full_list.html @@ -94,15 +94,15 @@