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)