Remove dead code and fix stale comments in filters.py
- Remove _filter_number() — defined but never called; take _FILTER_INPUT_CLASS with it since it was only used there. - Remove the isinstance(value/excluded, str) single-string guards in _filter_get_choice — JS always emits arrays, this was backward-compat dead code. - Remove identity-copy list comprehensions in PurchaseFilterBar; pass Purchase.TYPES and Purchase.OWNERSHIP_TYPES directly. - Fix stale section comment that said model fields "resolve selected ids to labels" — they now use labels embedded in the filter JSON. - Drop the now-unused escape import. https://claude.ai/code/session_01EyAJcMoDktLrY9tSbdHViA
This commit is contained in:
@@ -3,7 +3,6 @@
|
|||||||
from typing import NamedTuple
|
from typing import NamedTuple
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils.html import escape
|
|
||||||
from django.utils.safestring import SafeText, mark_safe
|
from django.utils.safestring import SafeText, mark_safe
|
||||||
|
|
||||||
from common.components.core import Component
|
from common.components.core import Component
|
||||||
@@ -34,13 +33,6 @@ class RangeValues(NamedTuple):
|
|||||||
_FILTER_LABEL_CLASS = "text-xs font-medium text-body uppercase tracking-wide"
|
_FILTER_LABEL_CLASS = "text-xs font-medium text-body uppercase tracking-wide"
|
||||||
|
|
||||||
|
|
||||||
_FILTER_INPUT_CLASS = (
|
|
||||||
"block w-full rounded-base border border-default-medium "
|
|
||||||
"bg-neutral-secondary-medium text-sm text-heading p-2 "
|
|
||||||
"focus:ring-brand focus:border-brand"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
_FILTER_CHECKBOX_CLASS = (
|
_FILTER_CHECKBOX_CLASS = (
|
||||||
"rounded border-default-medium bg-neutral-secondary-medium "
|
"rounded border-default-medium bg-neutral-secondary-medium "
|
||||||
"text-brand focus:ring-brand"
|
"text-brand focus:ring-brand"
|
||||||
@@ -71,17 +63,10 @@ def _filter_get_choice(existing: dict, field: str) -> FilterChoice:
|
|||||||
raw = existing.get(field, {})
|
raw = existing.get(field, {})
|
||||||
if not isinstance(raw, dict):
|
if not isinstance(raw, dict):
|
||||||
return FilterChoice([], [], "")
|
return FilterChoice([], [], "")
|
||||||
value = raw.get("value", [])
|
|
||||||
excluded = raw.get("excludes", [])
|
|
||||||
modifier = raw.get("modifier", "")
|
|
||||||
if isinstance(value, str):
|
|
||||||
value = [value]
|
|
||||||
if isinstance(excluded, str):
|
|
||||||
excluded = [excluded]
|
|
||||||
return FilterChoice(
|
return FilterChoice(
|
||||||
selected=_extract_labeled(value or []),
|
selected=_extract_labeled(raw.get("value") or []),
|
||||||
excluded=_extract_labeled(excluded or []),
|
excluded=_extract_labeled(raw.get("excludes") or []),
|
||||||
modifier=modifier or "",
|
modifier=raw.get("modifier") or "",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -103,8 +88,8 @@ def _parse_bool(existing: dict, key: str) -> bool:
|
|||||||
|
|
||||||
# ── FilterSelect adapters ────────────────────────────────────────────────────
|
# ── FilterSelect adapters ────────────────────────────────────────────────────
|
||||||
# Each list filter is a FilterSelect. Enum fields pre-render their small, fixed
|
# Each list filter is a FilterSelect. Enum fields pre-render their small, fixed
|
||||||
# option set; model-backed fields fetch from a search endpoint and only resolve
|
# option set; model-backed fields fetch from a search endpoint on demand, with
|
||||||
# the currently-selected ids to labels for their pills.
|
# labels embedded in the filter JSON so pills render without a DB round-trip.
|
||||||
|
|
||||||
_FILTER_PREFETCH = 20
|
_FILTER_PREFETCH = 20
|
||||||
|
|
||||||
@@ -181,23 +166,6 @@ def _filter_field(label: str, widget) -> SafeText:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def _filter_number(label, name, value="", placeholder="") -> SafeText:
|
|
||||||
return _filter_field(
|
|
||||||
label,
|
|
||||||
Component(
|
|
||||||
tag_name="input",
|
|
||||||
attributes=[
|
|
||||||
("type", "number"),
|
|
||||||
("name", escape(name)),
|
|
||||||
("id", escape(name)),
|
|
||||||
("value", escape(value)),
|
|
||||||
("placeholder", escape(placeholder)),
|
|
||||||
("class", _FILTER_INPUT_CLASS),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def _filter_checkbox(name: str, label: str, checked: bool) -> SafeText:
|
def _filter_checkbox(name: str, label: str, checked: bool) -> SafeText:
|
||||||
return Label(
|
return Label(
|
||||||
attributes=[("class", "flex items-center gap-2 text-sm text-heading")],
|
attributes=[("class", "flex items-center gap-2 text-sm text-heading")],
|
||||||
@@ -806,8 +774,8 @@ def PurchaseFilterBar(
|
|||||||
"""Collapsible filter bar for the Purchase list."""
|
"""Collapsible filter bar for the Purchase list."""
|
||||||
from games.models import Purchase
|
from games.models import Purchase
|
||||||
|
|
||||||
type_options = [(value, label) for value, label in Purchase.TYPES]
|
type_options = Purchase.TYPES
|
||||||
ownership_options = [(value, label) for value, label in Purchase.OWNERSHIP_TYPES]
|
ownership_options = Purchase.OWNERSHIP_TYPES
|
||||||
existing = _filter_parse(filter_json)
|
existing = _filter_parse(filter_json)
|
||||||
game_choice = _filter_get_choice(existing, "games")
|
game_choice = _filter_get_choice(existing, "games")
|
||||||
platform_choice = _filter_get_choice(existing, "platform")
|
platform_choice = _filter_get_choice(existing, "platform")
|
||||||
|
|||||||
Reference in New Issue
Block a user