From 1655af375ce908b3f078f599b6e00c462ca34bb1 Mon Sep 17 00:00:00 2001 From: Colin Maudry Date: Thu, 16 Apr 2026 11:07:59 +0200 Subject: [PATCH] =?UTF-8?q?arbre/liste=5Fmarches=5Forg.py=20:=20requ=C3=AA?= =?UTF-8?q?tes=20DuckDB=20pour=20les=20listes=20de=20march=C3=A9s=20(#71)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/arbre/liste_marches_org.py | 54 ++++++++++++++-------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/src/pages/arbre/liste_marches_org.py b/src/pages/arbre/liste_marches_org.py index 2184d55..9ab40ba 100644 --- a/src/pages/arbre/liste_marches_org.py +++ b/src/pages/arbre/liste_marches_org.py @@ -1,12 +1,8 @@ import polars as pl from dash import Input, Output, callback, dcc, html, register_page -from src.utils import ( - df_acheteurs, - df_acheteurs_marches, - df_titulaires, - df_titulaires_marches, -) +from src.db import get_cursor +from src.utils import df_acheteurs, df_titulaires name = "Liste des marchés publics" @@ -68,28 +64,34 @@ def liste_marches(url): org_id = url.split("/")[-1] def make_link_list() -> list: - link_list = [] - if org_type == "acheteur": - df = df_acheteurs_marches - elif org_type == "titulaire": - df = df_titulaires_marches - else: + table = ( + "acheteurs_marches" + if org_type == "acheteur" + else "titulaires_marches" + if org_type == "titulaire" + else None + ) + if table is None: raise ValueError - - df = df.filter(pl.col(f"{org_type}_id") == org_id) - - for row in df.iter_rows(named=True): - li = html.Li( - [ - dcc.Link( - row["objet"], - href=f"/marches/{row['uid']}", - title=f"Marchés public attribué : {row['objet']}", - ) - ] + rows = ( + get_cursor() + .execute( + f"SELECT uid, objet FROM {table} WHERE {org_type}_id = ?", + [org_id], ) - link_list.append(li) - return link_list + .fetchall() + ) + + return [ + html.Li( + dcc.Link( + objet, + href=f"/marches/{uid}", + title=f"Marchés public attribué : {objet}", + ) + ) + for uid, objet in rows + ] nom, verbe = make_org_nom_verbe(org_type, org_id)