map view (Leaflet + OSM), iOS switches, Alarm → Benachrichtigungen

* flats: new lat/lng columns (migration v3); alert geocodes every new flat
  through googlemaps and ships coords in the payload
* web: CSP extended for unpkg (leaflet.css) + tile.openstreetmap.org
* Wohnungen tab: Liste/Karte view toggle (segmented, CSS-only via :has(),
  selection persisted in localStorage). Karte shows passende flats as Pins
  on an OSM tile map; Popup per Pin mit Adresse, Zimmer/m²/€ und Link
* Top-strip toggles are now proper iOS-style toggle switches (single
  rounded knob sliding in a pill, red when on), no descriptive subtitle
* Alarm-Karte verlinkt jetzt auf /einstellungen/benachrichtigungen
  (Filter-Karte bleibt /einstellungen/filter)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Moritz 2026-04-21 12:02:40 +02:00
parent d9468f6814
commit 376551213a
8 changed files with 239 additions and 83 deletions

View file

@ -28,6 +28,7 @@ class Flat:
self.id = self.link # we could use data.get('id', None) but link is easier to debug
self.gmaps = maps.Maps()
self._connectivity = None
self._coords = None
self.address_link_gmaps = f"https://www.google.com/maps/search/?api=1&query={quote(self.address)}"
def __str__(self):
@ -59,6 +60,12 @@ class Flat:
self._connectivity = self.gmaps.calculate_score(self.address)
return self._connectivity
@property
def coords(self):
if self._coords is None:
self._coords = self.gmaps.geocode(self.address) or (None, None)
return self._coords
@property
def display_address(self):
if ',' in self.address:

View file

@ -32,6 +32,7 @@ class FlatAlerter:
def _flat_payload(self, flat: Flat) -> dict:
c = flat.connectivity
lat, lng = flat.coords
return {
"id": flat.id,
"link": flat.link,
@ -53,6 +54,8 @@ class FlatAlerter:
"energy_value": flat.energy_value,
"energy_certificate": flat.energy_certificate,
"address_link_gmaps": flat.address_link_gmaps,
"lat": lat,
"lng": lng,
"connectivity": {
"morning_time": c.get("morning_time", 0),
"morning_transfers": c.get("morning_transfers", 0),

View file

@ -23,6 +23,20 @@ class Maps:
def __init__(self):
self.gmaps = googlemaps.Client(key=GMAPS_API_KEY)
def geocode(self, address):
"""Return (lat, lng) or None for a Berlin address string."""
if not address:
return None
try:
res = self.gmaps.geocode(f"{address}, Berlin, Germany")
if not res:
return None
loc = res[0]["geometry"]["location"]
return (float(loc["lat"]), float(loc["lng"]))
except Exception as e:
logger.warning("geocode failed for %r: %s", address, e)
return None
def _get_next_weekday(self, date, weekday):
days_ahead = weekday - date.weekday()
if days_ahead <= 0: