refactor: move track_search out of filter_table_data into callers (#72)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -35,6 +35,7 @@ from src.utils.table import (
|
|||||||
prepare_table_data,
|
prepare_table_data,
|
||||||
sort_table_data,
|
sort_table_data,
|
||||||
)
|
)
|
||||||
|
from src.utils.tracking import track_search
|
||||||
|
|
||||||
|
|
||||||
def get_title(acheteur_id: str | None = None) -> str:
|
def get_title(acheteur_id: str | None = None) -> str:
|
||||||
@@ -424,6 +425,7 @@ def download_filtered_acheteur_data(
|
|||||||
lff = lff.drop(hidden_columns)
|
lff = lff.drop(hidden_columns)
|
||||||
|
|
||||||
if filter_query:
|
if filter_query:
|
||||||
|
track_search(filter_query, "ach download")
|
||||||
lff = filter_table_data(lff, filter_query, "ach download")
|
lff = filter_table_data(lff, filter_query, "ach download")
|
||||||
|
|
||||||
if len(sort_by) > 0:
|
if len(sort_by) > 0:
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ from src.utils.table import (
|
|||||||
prepare_table_data,
|
prepare_table_data,
|
||||||
sort_table_data,
|
sort_table_data,
|
||||||
)
|
)
|
||||||
|
from src.utils.tracking import track_search
|
||||||
|
|
||||||
update_date_timestamp = os.path.getmtime(os.getenv("DATA_FILE_PARQUET_PATH"))
|
update_date_timestamp = os.path.getmtime(os.getenv("DATA_FILE_PARQUET_PATH"))
|
||||||
update_date = datetime.fromtimestamp(update_date_timestamp).strftime("%d/%m/%Y")
|
update_date = datetime.fromtimestamp(update_date_timestamp).strftime("%d/%m/%Y")
|
||||||
@@ -322,6 +323,7 @@ def download_data(n_clicks, filter_query, sort_by, hidden_columns: list = None):
|
|||||||
lff = lff.drop(hidden_columns)
|
lff = lff.drop(hidden_columns)
|
||||||
|
|
||||||
if filter_query:
|
if filter_query:
|
||||||
|
track_search(filter_query, "tab download")
|
||||||
lff = filter_table_data(lff, filter_query, "tab download")
|
lff = filter_table_data(lff, filter_query, "tab download")
|
||||||
|
|
||||||
if sort_by and len(sort_by) > 0:
|
if sort_by and len(sort_by) > 0:
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ from src.utils.table import (
|
|||||||
prepare_table_data,
|
prepare_table_data,
|
||||||
sort_table_data,
|
sort_table_data,
|
||||||
)
|
)
|
||||||
|
from src.utils.tracking import track_search
|
||||||
|
|
||||||
|
|
||||||
def get_title(titulaire_id: str = None) -> str:
|
def get_title(titulaire_id: str = None) -> str:
|
||||||
@@ -440,6 +441,7 @@ def download_filtered_titulaire_data(
|
|||||||
lff = lff.drop(hidden_columns)
|
lff = lff.drop(hidden_columns)
|
||||||
|
|
||||||
if filter_query:
|
if filter_query:
|
||||||
|
track_search(filter_query, "titu download")
|
||||||
lff = filter_table_data(lff, filter_query, "titu download")
|
lff = filter_table_data(lff, filter_query, "titu download")
|
||||||
|
|
||||||
if len(sort_by) > 0:
|
if len(sort_by) > 0:
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ from src.db import query_marches, schema
|
|||||||
from src.utils import logger
|
from src.utils import logger
|
||||||
from src.utils.data import DATA_SCHEMA
|
from src.utils.data import DATA_SCHEMA
|
||||||
from src.utils.frontend import get_button_properties
|
from src.utils.frontend import get_button_properties
|
||||||
from src.utils.tracking import track_search
|
|
||||||
|
|
||||||
|
|
||||||
def split_filter_part(filter_part):
|
def split_filter_part(filter_part):
|
||||||
@@ -210,7 +209,6 @@ def filter_table_data(
|
|||||||
lff: pl.LazyFrame, filter_query: str, filter_source: str
|
lff: pl.LazyFrame, filter_query: str, filter_source: str
|
||||||
) -> pl.LazyFrame:
|
) -> pl.LazyFrame:
|
||||||
_schema = lff.collect_schema()
|
_schema = lff.collect_schema()
|
||||||
track_search(filter_query, filter_source)
|
|
||||||
filtering_expressions = filter_query.split(" && ")
|
filtering_expressions = filter_query.split(" && ")
|
||||||
for filter_part in filtering_expressions:
|
for filter_part in filtering_expressions:
|
||||||
col_name, operator, filter_value = split_filter_part(filter_part)
|
col_name, operator, filter_value = split_filter_part(filter_part)
|
||||||
|
|||||||
@@ -30,3 +30,17 @@ def test_table_module_imports():
|
|||||||
from src.utils import table
|
from src.utils import table
|
||||||
|
|
||||||
assert hasattr(table, "prepare_table_data")
|
assert hasattr(table, "prepare_table_data")
|
||||||
|
|
||||||
|
|
||||||
|
def test_filter_table_data_does_not_call_track_search(monkeypatch, sample_lff):
|
||||||
|
from src.utils import table
|
||||||
|
|
||||||
|
calls = []
|
||||||
|
monkeypatch.setattr(table, "track_search", lambda *a, **kw: calls.append(a))
|
||||||
|
|
||||||
|
result = table.filter_table_data(
|
||||||
|
sample_lff, "{objet} icontains travaux", "tableau"
|
||||||
|
).collect()
|
||||||
|
|
||||||
|
assert calls == []
|
||||||
|
assert result.height == 1
|
||||||
|
|||||||
Reference in New Issue
Block a user