departement.py : requêtes DuckDB sur acheteurs_departement et titulaires_departement (#71)
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
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 departements, df_acheteurs_departement, df_titulaires_departement
|
from src.db import get_cursor
|
||||||
|
from src.utils import departements
|
||||||
|
|
||||||
name = "Département"
|
name = "Département"
|
||||||
|
|
||||||
@@ -39,29 +39,42 @@ def departement_marches(url):
|
|||||||
departement = url.split("/")[-1]
|
departement = url.split("/")[-1]
|
||||||
|
|
||||||
def make_link_list(org_type) -> list:
|
def make_link_list(org_type) -> list:
|
||||||
link_list = []
|
table = (
|
||||||
if org_type == "acheteur":
|
"acheteurs_departement"
|
||||||
df = df_acheteurs_departement
|
if org_type == "acheteur"
|
||||||
elif org_type == "titulaire":
|
else "titulaires_departement"
|
||||||
df = df_titulaires_departement
|
if org_type == "titulaire"
|
||||||
else:
|
else None
|
||||||
|
)
|
||||||
|
if table is None:
|
||||||
raise ValueError
|
raise ValueError
|
||||||
|
col_prefix = org_type
|
||||||
|
rows = (
|
||||||
|
get_cursor()
|
||||||
|
.execute(
|
||||||
|
f"SELECT {col_prefix}_id, {col_prefix}_nom "
|
||||||
|
f"FROM {table} "
|
||||||
|
f"WHERE {col_prefix}_departement_code = ? "
|
||||||
|
f"ORDER BY {col_prefix}_nom",
|
||||||
|
[departement],
|
||||||
|
)
|
||||||
|
.fetchall()
|
||||||
|
)
|
||||||
|
|
||||||
df = df.filter(pl.col(f"{org_type}_departement_code") == departement)
|
link_list = []
|
||||||
|
for org_id, org_nom in rows:
|
||||||
for row in df.iter_rows(named=True):
|
|
||||||
li = html.Li(
|
li = html.Li(
|
||||||
[
|
[
|
||||||
dcc.Link(
|
dcc.Link(
|
||||||
row[f"{org_type}_nom"],
|
org_nom,
|
||||||
href=url + f"/{org_type}/{row[f'{org_type}_id']}",
|
href=url + f"/{org_type}/{org_id}",
|
||||||
title=f"Marchés publics de {row[f'{org_type}_nom']}",
|
title=f"Marchés publics de {org_nom}",
|
||||||
),
|
),
|
||||||
" ",
|
" ",
|
||||||
dcc.Link(
|
dcc.Link(
|
||||||
"(page dédiée)",
|
"(page dédiée)",
|
||||||
href=f"/{org_type}s/{row[f'{org_type}_id']}",
|
href=f"/{org_type}s/{org_id}",
|
||||||
title=f"Page dédiée aux marchés publics de {row[f'{org_type}_nom']}",
|
title=f"Page dédiée aux marchés publics de {org_nom}",
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user