Simplifications du code #72

This commit is contained in:
Colin Maudry
2026-04-22 17:17:54 +02:00
parent 1e67d329d0
commit 72d4881796
3 changed files with 5 additions and 13 deletions
+1 -2
View File
@@ -470,13 +470,12 @@ def prepare_table_data(
if data is None: if data is None:
sort_by_key = normalize_sort_by(sort_by) 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, filter_query=filter_query,
sort_by_key=sort_by_key, sort_by_key=sort_by_key,
page_current=page_current, page_current=page_current,
page_size=page_size, page_size=page_size,
) )
height = total
already_paginated = True already_paginated = True
else: else:
already_paginated = False already_paginated = False
+3 -10
View File
@@ -28,19 +28,13 @@ def filter_query_to_sql(filter_query: str, schema: pl.Schema) -> tuple[str, list
continue continue
col_type = schema[col_name] col_type = schema[col_name]
is_numeric = isinstance( is_numeric = col_type.is_numeric()
col_type, (pl.Int8, pl.Int16, pl.Int32, pl.Int64, pl.Float32, pl.Float64)
)
col_is_date = col_type == pl.Date col_is_date = col_type == pl.Date
quoted_col = f'"{col_name}"' quoted_col = f'"{col_name}"'
if is_numeric: if is_numeric:
try: try:
value = ( value = int(raw_value) if col_type.is_integer() else float(raw_value)
int(raw_value)
if isinstance(col_type, (pl.Int8, pl.Int16, pl.Int32, pl.Int64))
else float(raw_value)
)
except ValueError: except ValueError:
logger.warning(f"Valeur numérique invalide ignorée : {raw_value!r}") logger.warning(f"Valeur numérique invalide ignorée : {raw_value!r}")
continue continue
@@ -65,8 +59,6 @@ def filter_query_to_sql(filter_query: str, schema: pl.Schema) -> tuple[str, list
like = value[:-1] + "%" like = value[:-1] + "%"
elif value.startswith("*") and not value.endswith("*"): elif value.startswith("*") and not value.endswith("*"):
like = "%" + value[1:] like = "%" + value[1:]
elif value.startswith("*") and value.endswith("*"):
like = "%" + value[1:-1] + "%"
else: else:
like = "%" + value + "%" like = "%" + value + "%"
target = f"CAST({quoted_col} AS VARCHAR)" if col_is_date else quoted_col 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}") logger.warning(f"Tri sur colonne inconnue ignoré : {col!r}")
continue continue
if direction not in ("asc", "desc"): if direction not in ("asc", "desc"):
logger.warning(f"Tri sur direction inconnue ignoré : {direction!r}")
continue continue
fragments.append(f'"{col}" {direction.upper()} NULLS LAST') fragments.append(f'"{col}" {direction.upper()} NULLS LAST')
Generated
+1 -1
View File
@@ -760,7 +760,7 @@ wheels = [
[[package]] [[package]]
name = "decp-info" name = "decp-info"
version = "2.7.2" version = "2.7.3"
source = { virtual = "." } source = { virtual = "." }
dependencies = [ dependencies = [
{ name = "dash", extra = ["compress"] }, { name = "dash", extra = ["compress"] },