map debug + coord backfill, remove email channel, countdown label

- Surface "X/Y passende Wohnungen mit Koordinaten" on the Karte view +
  admin-only "Koordinaten nachladen" button (POST /actions/backfill-coords)
  that geocodes missing flats via Google Maps directly from the web container
- Add googlemaps dep + GMAPS_API_KEY env to web service
- Light console.log in map.js ("rendering N/M markers", "building Leaflet…")
  so the browser DevTools shows what's happening
- Drop e-mail channel from notifications UI, notify dispatcher, and _alert_status;
  coerce legacy 'email' channel rows back to 'ui' on save
- Countdown said "Aktualisierung läuft…" next to "nächste Aktualisierung" →
  shortened to "aktualisiere…"

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
EiSiMo 2026-04-21 13:42:21 +02:00
parent 51b6b02b24
commit 0c58242ce7
11 changed files with 149 additions and 58 deletions

View file

@ -33,6 +33,7 @@ except Exception:
BERLIN_TZ = timezone.utc
import db
import geocode
import notifications
import retention
from apply_client import ApplyClient, _row_to_profile
@ -220,9 +221,9 @@ def _has_filters(f) -> bool:
def _alert_status(notifications_row) -> tuple[str, str]:
"""Return (label, chip_kind) for the user's alarm (notification) setup.
'aktiv' only if a real push channel (telegram/email) is configured with
credentials. 'ui' is not a real alarm the dashboard already shows
matches when you happen to be looking.
'aktiv' only if a real push channel is configured with credentials.
'ui' is not a real alarm the dashboard already shows matches when you
happen to be looking.
"""
if not notifications_row:
return "nicht eingerichtet", "warn"
@ -231,10 +232,6 @@ def _alert_status(notifications_row) -> tuple[str, str]:
if notifications_row["telegram_bot_token"] and notifications_row["telegram_chat_id"]:
return "aktiv (Telegram)", "ok"
return "unvollständig", "warn"
if ch == "email":
if notifications_row["email_address"]:
return "aktiv (E-Mail)", "ok"
return "unvollständig", "warn"
return "nicht eingerichtet", "warn"
@ -405,6 +402,12 @@ def _wohnungen_context(user) -> dict:
flats_view.append({"row": f, "last": last})
rejected_view = db.rejected_flats(uid)
matched_count = len(flats_view)
matched_with_coords = sum(
1 for item in flats_view
if item["row"]["lat"] is not None and item["row"]["lng"] is not None
)
matched_without_coords = matched_count - matched_with_coords
allowed, reason = _manual_apply_allowed()
alert_label, alert_chip = _alert_status(notif_row)
@ -426,6 +429,10 @@ def _wohnungen_context(user) -> dict:
"flats": flats_view,
"rejected_flats": rejected_view,
"map_points": map_points,
"map_matched_total": matched_count,
"map_matched_with_coords": matched_with_coords,
"map_matched_without_coords": matched_without_coords,
"gmaps_available": bool(geocode._get_client() is not None),
"has_filters": _has_filters(filters_row),
"alert_label": alert_label,
"alert_chip": alert_chip,
@ -551,6 +558,31 @@ async def action_reject(
return _wohnungen_partial_or_redirect(request, user)
@app.post("/actions/backfill-coords")
async def action_backfill_coords(
request: Request,
csrf: str = Form(...),
admin=Depends(require_admin),
):
require_csrf(admin["id"], csrf)
rows = db.flats_missing_coords(limit=500)
total = len(rows)
resolved = 0
skipped = 0
for row in rows:
coords = geocode.geocode(row["address"])
if coords is None:
skipped += 1
continue
db.set_flat_coords(row["id"], coords[0], coords[1])
resolved += 1
summary = f"{resolved}/{total} geocoded, {skipped} übersprungen"
logger.info("coord backfill: %s", summary)
db.log_audit(admin["username"], "coords.backfill", summary,
user_id=admin["id"], ip=client_ip(request))
return _wohnungen_partial_or_redirect(request, admin)
@app.post("/actions/unreject")
async def action_unreject(
request: Request,
@ -854,11 +886,14 @@ async def action_notifications(request: Request, user=Depends(require_user)):
form = await request.form()
require_csrf(user["id"], form.get("csrf", ""))
def _b(n): return 1 if form.get(n, "").lower() in ("on", "true", "1", "yes") else 0
channel = form.get("channel", "ui")
if channel not in ("ui", "telegram"):
channel = "ui"
db.update_notifications(user["id"], {
"channel": form.get("channel", "ui"),
"channel": channel,
"telegram_bot_token": form.get("telegram_bot_token", ""),
"telegram_chat_id": form.get("telegram_chat_id", ""),
"email_address": form.get("email_address", ""),
"email_address": "",
"notify_on_match": _b("notify_on_match"),
"notify_on_apply_success": _b("notify_on_apply_success"),
"notify_on_apply_fail": _b("notify_on_apply_fail"),