Custom filter logic
This commit is contained in:
+28
-23
@@ -8,6 +8,7 @@ from src.figures import DataTable, point_on_map
|
|||||||
from src.utils import (
|
from src.utils import (
|
||||||
add_links_in_dict,
|
add_links_in_dict,
|
||||||
df,
|
df,
|
||||||
|
filter_table_data,
|
||||||
format_number,
|
format_number,
|
||||||
format_values,
|
format_values,
|
||||||
get_annuaire_data,
|
get_annuaire_data,
|
||||||
@@ -26,6 +27,16 @@ register_page(
|
|||||||
order=5,
|
order=5,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
datatable = html.Div(
|
||||||
|
className="marches_table",
|
||||||
|
children=DataTable(
|
||||||
|
dtid="acheteur_datatable",
|
||||||
|
page_action="native",
|
||||||
|
filter_action="custom",
|
||||||
|
page_size=10,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
layout = [
|
layout = [
|
||||||
dcc.Store(id="acheteur_data", storage_type="memory"),
|
dcc.Store(id="acheteur_data", storage_type="memory"),
|
||||||
dcc.Location(id="url", refresh="callback-nav"),
|
dcc.Location(id="url", refresh="callback-nav"),
|
||||||
@@ -101,7 +112,7 @@ layout = [
|
|||||||
),
|
),
|
||||||
# récupérer les données de l'acheteur sur l'api annuaire
|
# récupérer les données de l'acheteur sur l'api annuaire
|
||||||
html.H3("Derniers marchés publics attribués"),
|
html.H3("Derniers marchés publics attribués"),
|
||||||
html.Div(id="acheteur_last_marches", children=""),
|
html.Div(id="acheteur_last_marches", children=datatable),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
@@ -200,43 +211,37 @@ def get_acheteur_marches_data(url, acheteur_year: str) -> list[dict]:
|
|||||||
acheteur_year = int(acheteur_year)
|
acheteur_year = int(acheteur_year)
|
||||||
lff = lff.filter(pl.col("dateNotification").dt.year() == acheteur_year)
|
lff = lff.filter(pl.col("dateNotification").dt.year() == acheteur_year)
|
||||||
lff = lff.sort(["dateNotification", "id"], descending=True, nulls_last=True)
|
lff = lff.sort(["dateNotification", "id"], descending=True, nulls_last=True)
|
||||||
|
lff = lff.fill_null("")
|
||||||
|
|
||||||
data = lff.collect(engine="streaming").to_dicts()
|
data = lff.collect(engine="streaming").to_dicts()
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
@callback(
|
@callback(
|
||||||
Output(component_id="acheteur_last_marches", component_property="children"),
|
Output(component_id="acheteur_datatable", component_property="data"),
|
||||||
|
Output(component_id="acheteur_datatable", component_property="columns"),
|
||||||
|
Output(component_id="acheteur_datatable", component_property="tooltip_header"),
|
||||||
Input(component_id="acheteur_data", component_property="data"),
|
Input(component_id="acheteur_data", component_property="data"),
|
||||||
|
Input(component_id="acheteur_datatable", component_property="filter_query"),
|
||||||
)
|
)
|
||||||
def get_last_marches_table(data) -> html.Div:
|
def get_last_marches_data(data, filter_query) -> tuple[list[dict], list, list]:
|
||||||
dff = pl.DataFrame(data)
|
lff: pl.LazyFrame = pl.LazyFrame(data)
|
||||||
if dff.height == 0:
|
if filter_query:
|
||||||
return html.Div(html.P("Aucun marché trouvé."))
|
lff = filter_table_data(lff, filter_query)
|
||||||
dff = dff.cast(pl.String)
|
|
||||||
dff = dff.fill_null("")
|
lff = lff.cast(pl.String)
|
||||||
dff = format_values(dff)
|
dff: pl.DataFrame = format_values(lff.collect())
|
||||||
columns, tooltip = setup_table_columns(
|
columns, tooltip_header = setup_table_columns(
|
||||||
dff,
|
dff,
|
||||||
hideable=False,
|
hideable=False,
|
||||||
exclude=["titulaire_id", "titulaire_typeIdentifiant", "uid"],
|
exclude=["titulaire_id", "titulaire_typeIdentifiant", "uid"],
|
||||||
)
|
)
|
||||||
|
|
||||||
data = dff.to_dicts()
|
data = dff.to_dicts()
|
||||||
|
|
||||||
data = add_links_in_dict(data, "titulaire")
|
data = add_links_in_dict(data, "titulaire")
|
||||||
|
|
||||||
table = html.Div(
|
return data, columns, tooltip_header
|
||||||
className="marches_table",
|
|
||||||
children=DataTable(
|
|
||||||
dtid="acheteur_datatable",
|
|
||||||
data=data,
|
|
||||||
page_action="native",
|
|
||||||
filter_action="native",
|
|
||||||
columns=columns,
|
|
||||||
tooltip_header=tooltip,
|
|
||||||
page_size=10,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
return table
|
|
||||||
|
|
||||||
|
|
||||||
@callback(
|
@callback(
|
||||||
|
|||||||
Reference in New Issue
Block a user