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

@ -37,6 +37,17 @@ def flat_matches_filter(flat: dict, f: dict | None) -> bool:
if wbs_str and wbs_str not in ("kein", "nein", "no", "ohne", "-"):
return False
# Berlin-Bezirk filter. Empty string = no filter = all Bezirke match.
# When active, flats with an unknown/unmapped PLZ are excluded — if the
# user bothered to narrow by district, we shouldn't sneak in flats we
# couldn't place.
districts_csv = (f.get("districts") or "").strip()
if districts_csv:
selected = {d.strip() for d in districts_csv.split(",") if d.strip()}
flat_district = (flat.get("district") or "").strip()
if not flat_district or flat_district not in selected:
return False
return True