feat(filter): Berlin-Bezirk filter in Einstellungen

Adds a collapsible 12-Bezirk checkbox list to the filter tab. The UI
speaks Bezirke; internally the match runs on the PLZ extracted from
flat.address and resolved to a dominant Bezirk via a curated 187-PLZ
map (berlin_districts.py).

- Migration 0011 adds user_filters.districts (CSV of selected names)
- Empty stored value = no filter = all Bezirke ticked in the UI.
  Submitting "all ticked" or "none ticked" both normalise to empty
  so the defaults and the nuclear state mean the same thing.
- When a Bezirk filter is active, flats with an unknown/unmapped PLZ
  are excluded — if the user bothered to narrow by district, sneaking
  in unplaceable flats would be the wrong default.
- Filter summary on the Wohnungen page shows "N Bezirke" so it's
  visible the filter is active.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
EiSiMo 2026-04-23 10:05:55 +02:00
parent abd614604f
commit d13f9c5b6e
7 changed files with 202 additions and 20 deletions

View file

@ -270,6 +270,11 @@ MIGRATIONS: list[str] = [
ALTER TABLE flats ADD COLUMN offline_at TEXT;
CREATE INDEX IF NOT EXISTS idx_flats_offline ON flats(offline_at);
""",
# 0011: per-user Berlin-Bezirk filter. CSV of selected Bezirk names;
# empty = no filter (= all Bezirke match).
"""
ALTER TABLE user_filters ADD COLUMN districts TEXT NOT NULL DEFAULT '';
""",
]
@ -463,7 +468,7 @@ def get_filters(user_id: int) -> sqlite3.Row:
def update_filters(user_id: int, data: dict) -> None:
_ensure_user_rows(user_id)
allowed = {"rooms_min", "rooms_max", "max_rent", "min_size",
"wbs_required", "max_age_hours"}
"wbs_required", "max_age_hours", "districts"}
clean = {k: data.get(k) for k in allowed if k in data}
if not clean:
return