From df04286a4aab6cf594f50d45abc0dd60f8016806 Mon Sep 17 00:00:00 2001 From: Colin Maudry Date: Sat, 27 Sep 2025 11:48:57 +0200 Subject: [PATCH] =?UTF-8?q?Derniers=20march=C3=A9=20notifi=C3=A9s=20#28?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/assets/style.css | 5 ++- src/pages/acheteur.py | 69 ++++++++++++++++++++++++++++++--- src/pages/home.py | 89 ++++++++++++++++++++++--------------------- 3 files changed, 113 insertions(+), 50 deletions(-) diff --git a/src/assets/style.css b/src/assets/style.css index 2532b92..88f1e3f 100644 --- a/src/assets/style.css +++ b/src/assets/style.css @@ -71,7 +71,10 @@ td[data-dash-column="objet"] { } /* Alternance des couleurs pour les lignes */ -#table tr:nth-child(even) td { +.marches_table { + font-family: sans-serif; +} +.marches_table .cell-table tr:nth-child(even) td { background-color: #feeeee; } diff --git a/src/pages/acheteur.py b/src/pages/acheteur.py index 051d52b..f767e6b 100644 --- a/src/pages/acheteur.py +++ b/src/pages/acheteur.py @@ -1,5 +1,7 @@ -import dash -from dash import Input, Output, callback, dcc, html, register_page +import polars as pl +from dash import Input, Output, callback, dash_table, dcc, html, register_page + +from src.utils import lf register_page( __name__, @@ -11,14 +13,15 @@ register_page( # 21690123100011 -print(dash.page_registry["pages.acheteur"]) - layout = [ + dcc.Store(id="acheteur_data", storage_type="memory"), dcc.Location(id="url", refresh="callback-nav"), html.Div( className="container", children=[ html.H2(id="acheteur_title", children=""), + html.H3("Derniers marchés publics notifiés"), + html.Div(id="acheteur_last_marches", children=""), ], ), ] @@ -30,6 +33,60 @@ layout = [ ) def update_acheteur(url): acheteur_siret = url.split("/")[-1] - acheteur_title = acheteur_siret + if len(acheteur_siret) != 14: + return f"Le SIRET renseigné doit faire 14 caractères ({acheteur_siret})" - return acheteur_title + return acheteur_siret + + +@callback( + Output(component_id="acheteur_data", component_property="data"), + Input(component_id="url", component_property="pathname"), +) +def get_acheteur_marches_data(url) -> pl.LazyFrame: + acheteur_siret = url.split("/")[-1] + lff = lf.filter(pl.col("acheteur_id") == acheteur_siret) + lff = lff.select( + "uid", + "objet", + "dateNotification", + "titulaire_nom", + "montant", + "codeCPV", + "dureeMois", + ) + lff = lff.sort("dateNotification", descending=True, nulls_last=True) + data = lff.collect(engine="streaming").to_dicts() + return data + + +@callback( + Output(component_id="acheteur_last_marches", component_property="children"), + Input(component_id="acheteur_data", component_property="data"), +) +def get_last_marches_table(data) -> html.Div: + table = html.Div( + className="marches_table", + children=dash_table.DataTable( + data=data[:20], + style_cell_conditional=[ + { + "if": {"column_id": "objet"}, + "minWidth": "300px", + "textAlign": "left", + "overflow": "hidden", + "lineHeight": "14px", + "whiteSpace": "normal", + }, + { + "if": {"column_id": "titulaire_nom"}, + "minWidth": "200px", + "textAlign": "left", + "overflow": "hidden", + "lineHeight": "14px", + "whiteSpace": "normal", + }, + ], + ), + ) + return table diff --git a/src/pages/home.py b/src/pages/home.py index 31c1ca4..780bfad 100644 --- a/src/pages/home.py +++ b/src/pages/home.py @@ -47,49 +47,52 @@ schema = lf.collect_schema() title = "Tableau" register_page(__name__, path="/", title="decp.info", name=title, order=1) -datatable = dash_table.DataTable( - cell_selectable=False, - id="table", - page_size=20, - page_current=0, - page_action="custom", - filter_action="custom", - filter_options={"case": "insensitive", "placeholder_text": "Filtrer..."}, - columns=[ - { - "name": i, - "id": i, - "presentation": "markdown", - "type": "text", - "format": {"nully": "N/A"}, - "hideable": True, - } - for i in lf.collect_schema().names() - ], - sort_action="custom", - sort_mode="multi", - sort_by=[], - row_deletable=False, - style_cell_conditional=[ - { - "if": {"column_id": "objet"}, - "minWidth": "350px", - "textAlign": "left", - "overflow": "hidden", - "lineHeight": "14px", - "whiteSpace": "normal", - }, - { - "if": {"column_id": "acheteur_nom"}, - "minWidth": "250px", - "textAlign": "left", - "overflow": "hidden", - "lineHeight": "14px", - "whiteSpace": "normal", - }, - ], - data_timestamp=0, - markdown_options={"html": True}, +datatable = html.Div( + className="marches_table", + children=dash_table.DataTable( + cell_selectable=False, + id="table", + page_size=20, + page_current=0, + page_action="custom", + filter_action="custom", + filter_options={"case": "insensitive", "placeholder_text": "Filtrer..."}, + columns=[ + { + "name": i, + "id": i, + "presentation": "markdown", + "type": "text", + "format": {"nully": "N/A"}, + "hideable": True, + } + for i in lf.collect_schema().names() + ], + sort_action="custom", + sort_mode="multi", + sort_by=[], + row_deletable=False, + style_cell_conditional=[ + { + "if": {"column_id": "objet"}, + "minWidth": "350px", + "textAlign": "left", + "overflow": "hidden", + "lineHeight": "14px", + "whiteSpace": "normal", + }, + { + "if": {"column_id": "acheteur_nom"}, + "minWidth": "250px", + "textAlign": "left", + "overflow": "hidden", + "lineHeight": "14px", + "whiteSpace": "normal", + }, + ], + data_timestamp=0, + markdown_options={"html": True}, + ), ) layout = [