wohnungen: preserve map across HTMX polls, add rejected section, drop €/m²

- #flats-map uses hx-preserve; marker data moved to <script type="application/json">
  sibling that diffs+updates instead of rebuilding Leaflet every poll (fixes
  whitescreen + tiles rendering outside the card)
- upsert_flat backfills lat/lng on existing rows missing coords (older flats
  scraped before the lat/lng migration now appear on the map once alert re-submits)
- collapsible "Abgelehnte Wohnungen" section at the bottom with Wiederherstellen
- remove €/m² column from the list

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
EiSiMo 2026-04-21 13:33:55 +02:00
parent 4fd0b50a43
commit 51b6b02b24
4 changed files with 155 additions and 45 deletions

View file

@ -395,8 +395,17 @@ def update_preferences(user_id: int, data: dict) -> None:
def upsert_flat(payload: dict) -> bool:
flat_id = str(payload["id"])
with _lock:
existing = _conn.execute("SELECT id FROM flats WHERE id = ?", (flat_id,)).fetchone()
existing = _conn.execute(
"SELECT id, lat, lng FROM flats WHERE id = ?", (flat_id,)
).fetchone()
if existing:
# Backfill coords on old rows that pre-date the lat/lng migration.
if (existing["lat"] is None or existing["lng"] is None) \
and payload.get("lat") is not None and payload.get("lng") is not None:
_conn.execute(
"UPDATE flats SET lat = ?, lng = ? WHERE id = ?",
(payload["lat"], payload["lng"], flat_id),
)
return False
c = payload.get("connectivity") or {}
_conn.execute(
@ -508,6 +517,16 @@ def rejected_flat_ids(user_id: int) -> set[str]:
return {row["flat_id"] for row in rows}
def rejected_flats(user_id: int, limit: int = 200) -> list[sqlite3.Row]:
return list(_conn.execute(
"""SELECT f.*, r.rejected_at
FROM flat_rejections r JOIN flats f ON f.id = r.flat_id
WHERE r.user_id = ?
ORDER BY r.rejected_at DESC LIMIT ?""",
(user_id, limit),
).fetchall())
def last_application_for_flat(user_id: int, flat_id: str) -> Optional[sqlite3.Row]:
return _conn.execute(
"""SELECT * FROM applications