From 72d48817961afa2a5538b7969f2cb016c8337040 Mon Sep 17 00:00:00 2001 From: Colin Maudry Date: Wed, 22 Apr 2026 17:17:54 +0200 Subject: [PATCH] Simplifications du code #72 --- src/utils/table.py | 3 +-- src/utils/table_sql.py | 13 +++---------- uv.lock | 2 +- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/utils/table.py b/src/utils/table.py index 9e47142..e3b59a8 100644 --- a/src/utils/table.py +++ b/src/utils/table.py @@ -470,13 +470,12 @@ def prepare_table_data( if data is None: sort_by_key = normalize_sort_by(sort_by) - dff, total, total_unique = _fetch_page_sql( + dff, height, total_unique = _fetch_page_sql( filter_query=filter_query, sort_by_key=sort_by_key, page_current=page_current, page_size=page_size, ) - height = total already_paginated = True else: already_paginated = False diff --git a/src/utils/table_sql.py b/src/utils/table_sql.py index f48ea35..67d7dcc 100644 --- a/src/utils/table_sql.py +++ b/src/utils/table_sql.py @@ -28,19 +28,13 @@ def filter_query_to_sql(filter_query: str, schema: pl.Schema) -> tuple[str, list continue col_type = schema[col_name] - is_numeric = isinstance( - col_type, (pl.Int8, pl.Int16, pl.Int32, pl.Int64, pl.Float32, pl.Float64) - ) + is_numeric = col_type.is_numeric() col_is_date = col_type == pl.Date quoted_col = f'"{col_name}"' if is_numeric: try: - value = ( - int(raw_value) - if isinstance(col_type, (pl.Int8, pl.Int16, pl.Int32, pl.Int64)) - else float(raw_value) - ) + value = int(raw_value) if col_type.is_integer() else float(raw_value) except ValueError: logger.warning(f"Valeur numérique invalide ignorée : {raw_value!r}") continue @@ -65,8 +59,6 @@ def filter_query_to_sql(filter_query: str, schema: pl.Schema) -> tuple[str, list like = value[:-1] + "%" elif value.startswith("*") and not value.endswith("*"): like = "%" + value[1:] - elif value.startswith("*") and value.endswith("*"): - like = "%" + value[1:-1] + "%" else: like = "%" + value + "%" target = f"CAST({quoted_col} AS VARCHAR)" if col_is_date else quoted_col @@ -103,6 +95,7 @@ def sort_by_to_sql(sort_by: list[dict] | None, schema: pl.Schema) -> str: logger.warning(f"Tri sur colonne inconnue ignoré : {col!r}") continue if direction not in ("asc", "desc"): + logger.warning(f"Tri sur direction inconnue ignoré : {direction!r}") continue fragments.append(f'"{col}" {direction.upper()} NULLS LAST') diff --git a/uv.lock b/uv.lock index 2c14012..0fd8ca1 100644 --- a/uv.lock +++ b/uv.lock @@ -760,7 +760,7 @@ wheels = [ [[package]] name = "decp-info" -version = "2.7.2" +version = "2.7.3" source = { virtual = "." } dependencies = [ { name = "dash", extra = ["compress"] },