arbre/liste_marches_org.py : requêtes DuckDB pour les listes de marchés (#71)

This commit is contained in:
Colin Maudry
2026-04-16 11:07:59 +02:00
parent cba3128b8f
commit 1655af375c
+25 -23
View File
@@ -1,12 +1,8 @@
import polars as pl import polars as pl
from dash import Input, Output, callback, dcc, html, register_page from dash import Input, Output, callback, dcc, html, register_page
from src.utils import ( from src.db import get_cursor
df_acheteurs, from src.utils import df_acheteurs, df_titulaires
df_acheteurs_marches,
df_titulaires,
df_titulaires_marches,
)
name = "Liste des marchés publics" name = "Liste des marchés publics"
@@ -68,28 +64,34 @@ def liste_marches(url):
org_id = url.split("/")[-1] org_id = url.split("/")[-1]
def make_link_list() -> list: def make_link_list() -> list:
link_list = [] table = (
if org_type == "acheteur": "acheteurs_marches"
df = df_acheteurs_marches if org_type == "acheteur"
elif org_type == "titulaire": else "titulaires_marches"
df = df_titulaires_marches if org_type == "titulaire"
else: else None
)
if table is None:
raise ValueError raise ValueError
rows = (
get_cursor()
.execute(
f"SELECT uid, objet FROM {table} WHERE {org_type}_id = ?",
[org_id],
)
.fetchall()
)
df = df.filter(pl.col(f"{org_type}_id") == org_id) return [
html.Li(
for row in df.iter_rows(named=True):
li = html.Li(
[
dcc.Link( dcc.Link(
row["objet"], objet,
href=f"/marches/{row['uid']}", href=f"/marches/{uid}",
title=f"Marchés public attribué : {row['objet']}", title=f"Marchés public attribué : {objet}",
) )
)
for uid, objet in rows
] ]
)
link_list.append(li)
return link_list
nom, verbe = make_org_nom_verbe(org_type, org_id) nom, verbe = make_org_nom_verbe(org_type, org_id)