Nettoyage des filtres aussi sur acheteur (clientside callback)
This commit is contained in:
+27
-1
@@ -2,7 +2,17 @@ import datetime
|
|||||||
|
|
||||||
import dash_bootstrap_components as dbc
|
import dash_bootstrap_components as dbc
|
||||||
import polars as pl
|
import polars as pl
|
||||||
from dash import Input, Output, State, callback, dcc, html, register_page
|
from dash import (
|
||||||
|
ClientsideFunction,
|
||||||
|
Input,
|
||||||
|
Output,
|
||||||
|
State,
|
||||||
|
callback,
|
||||||
|
clientside_callback,
|
||||||
|
dcc,
|
||||||
|
html,
|
||||||
|
register_page,
|
||||||
|
)
|
||||||
|
|
||||||
from src.callbacks import get_top_org_table
|
from src.callbacks import get_top_org_table
|
||||||
from src.figures import DataTable, make_column_picker, point_on_map
|
from src.figures import DataTable, make_column_picker, point_on_map
|
||||||
@@ -60,6 +70,7 @@ layout = [
|
|||||||
dcc.Store(id="acheteur-hidden-columns", storage_type="local"),
|
dcc.Store(id="acheteur-hidden-columns", storage_type="local"),
|
||||||
dcc.Store(id="acheteur-filters", storage_type="local"),
|
dcc.Store(id="acheteur-filters", storage_type="local"),
|
||||||
dcc.Store(id="acheteur-sort", storage_type="local"),
|
dcc.Store(id="acheteur-sort", storage_type="local"),
|
||||||
|
dcc.Store(id="filter-cleanup-trigger-acheteur"),
|
||||||
dcc.Location(id="acheteur_url", refresh="callback-nav"),
|
dcc.Location(id="acheteur_url", refresh="callback-nav"),
|
||||||
html.Div(
|
html.Div(
|
||||||
children=[
|
children=[
|
||||||
@@ -292,12 +303,14 @@ def get_acheteur_marches_data(url, acheteur_year: str) -> tuple:
|
|||||||
Output("btn-download-filtered-data-acheteur", "disabled"),
|
Output("btn-download-filtered-data-acheteur", "disabled"),
|
||||||
Output("btn-download-filtered-data-acheteur", "children"),
|
Output("btn-download-filtered-data-acheteur", "children"),
|
||||||
Output("btn-download-filtered-data-acheteur", "title"),
|
Output("btn-download-filtered-data-acheteur", "title"),
|
||||||
|
Output("filter-cleanup-trigger-acheteur", "data", allow_duplicate=True),
|
||||||
Input("acheteur_data", "data"),
|
Input("acheteur_data", "data"),
|
||||||
Input("acheteur_datatable", "page_current"),
|
Input("acheteur_datatable", "page_current"),
|
||||||
Input("acheteur_datatable", "page_size"),
|
Input("acheteur_datatable", "page_size"),
|
||||||
Input("acheteur-filters", "data"),
|
Input("acheteur-filters", "data"),
|
||||||
Input("acheteur-sort", "data"),
|
Input("acheteur-sort", "data"),
|
||||||
State("acheteur_datatable", "data_timestamp"),
|
State("acheteur_datatable", "data_timestamp"),
|
||||||
|
prevent_initial_call=True,
|
||||||
)
|
)
|
||||||
def get_last_marches_data(
|
def get_last_marches_data(
|
||||||
data, page_current, page_size, filter_query, sort_by, data_timestamp
|
data, page_current, page_size, filter_query, sort_by, data_timestamp
|
||||||
@@ -376,6 +389,19 @@ def download_filtered_acheteur_data(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# Pour nettoyer les icontains et i< des filtres
|
||||||
|
# voir aussi src/assets/dash_clientside.js
|
||||||
|
clientside_callback(
|
||||||
|
ClientsideFunction(
|
||||||
|
namespace="clientside",
|
||||||
|
function_name="clean_filters",
|
||||||
|
),
|
||||||
|
Output("filter-cleanup-trigger-acheteur", "data", allow_duplicate=True),
|
||||||
|
Input("filter-cleanup-trigger-acheteur", "data"),
|
||||||
|
prevent_initial_call=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@callback(
|
@callback(
|
||||||
Output("acheteur-hidden-columns", "data", allow_duplicate=True),
|
Output("acheteur-hidden-columns", "data", allow_duplicate=True),
|
||||||
Input("acheteur_column_list", "selected_rows"),
|
Input("acheteur_column_list", "selected_rows"),
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ datatable = html.Div(
|
|||||||
|
|
||||||
layout = [
|
layout = [
|
||||||
dcc.Location(id="tableau_url", refresh=False),
|
dcc.Location(id="tableau_url", refresh=False),
|
||||||
dcc.Store(id="filter-cleanup-trigger"),
|
dcc.Store(id="filter-cleanup-trigger-tableau"),
|
||||||
dcc.Store(id="tableau-hidden-columns", storage_type="local"),
|
dcc.Store(id="tableau-hidden-columns", storage_type="local"),
|
||||||
dcc.Store(id="tableau-filters", storage_type="local"),
|
dcc.Store(id="tableau-filters", storage_type="local"),
|
||||||
dcc.Store(id="tableau-sort", storage_type="local"),
|
dcc.Store(id="tableau-sort", storage_type="local"),
|
||||||
@@ -284,11 +284,13 @@ layout = [
|
|||||||
Output("btn-download-data", "disabled"),
|
Output("btn-download-data", "disabled"),
|
||||||
Output("btn-download-data", "children"),
|
Output("btn-download-data", "children"),
|
||||||
Output("btn-download-data", "title"),
|
Output("btn-download-data", "title"),
|
||||||
|
Output("filter-cleanup-trigger-tableau", "data", allow_duplicate=True),
|
||||||
Input("tableau_datatable", "page_current"),
|
Input("tableau_datatable", "page_current"),
|
||||||
Input("tableau_datatable", "page_size"),
|
Input("tableau_datatable", "page_size"),
|
||||||
Input("tableau-filters", "data"),
|
Input("tableau-filters", "data"),
|
||||||
Input("tableau-sort", "data"),
|
Input("tableau-sort", "data"),
|
||||||
State("tableau_datatable", "data_timestamp"),
|
State("tableau_datatable", "data_timestamp"),
|
||||||
|
prevent_initial_call=True,
|
||||||
)
|
)
|
||||||
def update_table(page_current, page_size, filter_query, sort_by, data_timestamp):
|
def update_table(page_current, page_size, filter_query, sort_by, data_timestamp):
|
||||||
# if ctx.triggered_id != "url":
|
# if ctx.triggered_id != "url":
|
||||||
@@ -333,7 +335,7 @@ def download_data(n_clicks, filter_query, sort_by, hidden_columns: list = None):
|
|||||||
Output("tableau_datatable", "sort_by"),
|
Output("tableau_datatable", "sort_by"),
|
||||||
Output("tableau-hidden-columns", "data"),
|
Output("tableau-hidden-columns", "data"),
|
||||||
Output("tableau_url", "search"),
|
Output("tableau_url", "search"),
|
||||||
Output("filter-cleanup-trigger", "data"),
|
Output("filter-cleanup-trigger-tableau", "data"),
|
||||||
Input("tableau_url", "search"),
|
Input("tableau_url", "search"),
|
||||||
State("tableau-filters", "data"),
|
State("tableau-filters", "data"),
|
||||||
State("tableau-sort", "data"),
|
State("tableau-sort", "data"),
|
||||||
@@ -375,13 +377,15 @@ def restore_view_from_url(search, stored_filters, stored_sort):
|
|||||||
return filter_query, sort_by, hidden_columns, "", trigger_cleanup
|
return filter_query, sort_by, hidden_columns, "", trigger_cleanup
|
||||||
|
|
||||||
|
|
||||||
|
# Pour nettoyer les icontains et i< des filtres
|
||||||
|
# voir aussi src/assets/dash_clientside.js
|
||||||
clientside_callback(
|
clientside_callback(
|
||||||
ClientsideFunction(
|
ClientsideFunction(
|
||||||
namespace="clientside",
|
namespace="clientside",
|
||||||
function_name="clean_filters",
|
function_name="clean_filters",
|
||||||
),
|
),
|
||||||
Output("filter-cleanup-trigger", "data", allow_duplicate=True),
|
Output("filter-cleanup-trigger-tableau", "data", allow_duplicate=True),
|
||||||
Input("filter-cleanup-trigger", "data"),
|
Input("filter-cleanup-trigger-tableau", "data"),
|
||||||
prevent_initial_call=True,
|
prevent_initial_call=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
+7
-2
@@ -8,6 +8,7 @@ from time import localtime, sleep
|
|||||||
import dash
|
import dash
|
||||||
import polars as pl
|
import polars as pl
|
||||||
import polars.selectors as cs
|
import polars.selectors as cs
|
||||||
|
from dash import no_update
|
||||||
from httpx import get, post
|
from httpx import get, post
|
||||||
from polars.exceptions import ComputeError
|
from polars.exceptions import ComputeError
|
||||||
from unidecode import unidecode
|
from unidecode import unidecode
|
||||||
@@ -586,6 +587,8 @@ def prepare_table_data(
|
|||||||
if os.getenv("DEVELOPMENT").lower() == "true":
|
if os.getenv("DEVELOPMENT").lower() == "true":
|
||||||
logger.debug(" + + + + + + + + + + + + + + + + + + ")
|
logger.debug(" + + + + + + + + + + + + + + + + + + ")
|
||||||
|
|
||||||
|
trigger_cleanup = no_update
|
||||||
|
|
||||||
# Récupération des données
|
# Récupération des données
|
||||||
if isinstance(data, list):
|
if isinstance(data, list):
|
||||||
lff: pl.LazyFrame = pl.LazyFrame(data, strict=False, infer_schema_length=5000)
|
lff: pl.LazyFrame = pl.LazyFrame(data, strict=False, infer_schema_length=5000)
|
||||||
@@ -595,6 +598,7 @@ def prepare_table_data(
|
|||||||
# Application des filtres
|
# Application des filtres
|
||||||
if filter_query:
|
if filter_query:
|
||||||
lff = filter_table_data(lff, filter_query, source_table)
|
lff = filter_table_data(lff, filter_query, source_table)
|
||||||
|
trigger_cleanup = no_update if source_table == "tableau" else str(uuid.uuid4())
|
||||||
|
|
||||||
# Application des tris
|
# Application des tris
|
||||||
if len(sort_by) > 0:
|
if len(sort_by) > 0:
|
||||||
@@ -632,7 +636,7 @@ def prepare_table_data(
|
|||||||
dff = format_values(dff)
|
dff = format_values(dff)
|
||||||
|
|
||||||
# Récupération des colonnes et tooltip
|
# Récupération des colonnes et tooltip
|
||||||
columns, tooltip = setup_table_columns(dff)
|
table_columns, tooltip = setup_table_columns(dff)
|
||||||
|
|
||||||
dicts = dff.to_dicts()
|
dicts = dff.to_dicts()
|
||||||
|
|
||||||
@@ -641,13 +645,14 @@ def prepare_table_data(
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
dicts,
|
dicts,
|
||||||
columns,
|
table_columns,
|
||||||
tooltip,
|
tooltip,
|
||||||
data_timestamp + 1,
|
data_timestamp + 1,
|
||||||
nb_rows,
|
nb_rows,
|
||||||
download_disabled,
|
download_disabled,
|
||||||
download_text,
|
download_text,
|
||||||
download_title,
|
download_title,
|
||||||
|
trigger_cleanup,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user