From 026e479e5c8601046940376e4c7e6b8ff4ef1cbc Mon Sep 17 00:00:00 2001
From: Robert Metcalf <metcalfr@cardiff.ac.uk>
Date: Tue, 14 Dec 2021 02:06:58 +0000
Subject: [PATCH] handle addresses without latlong on interactive map

---
 database.py           | 7 +++++--
 static/scripts/map.js | 3 +++
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/database.py b/database.py
index 80aaa96..046e671 100644
--- a/database.py
+++ b/database.py
@@ -59,8 +59,11 @@ with Connection() as conn:
 def lookup_address(address: str):
 	with Connection() as conn:
 		conn.execute("SELECT latlong FROM AddressToLatLong WHERE address = ?", (address,))
-		res = conn.cursor.fetchone()[0]
-		(lat, long) = res.split(",")
+		res = conn.cursor.fetchone()
+		if res == None:
+			return None
+
+		(lat, long) = res[0].split(",")
 		return (float(lat), float(long))
 
 def set_address_latlong(address: str, latlong: Tuple[float, float]):
diff --git a/static/scripts/map.js b/static/scripts/map.js
index b914908..f33f6db 100644
--- a/static/scripts/map.js
+++ b/static/scripts/map.js
@@ -5,6 +5,9 @@ L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
 }).addTo(map);
 
 for (let workspace of mapData) {
+	if (workspace.latlong == null)
+		continue;
+
 	L.marker(workspace.latlong).addTo(map)
 		.bindPopup(`<div class="popup"><div><a href="/workspace/${ encodeURIComponent(workspace.id) }" class="popup-title">${
 			escapeHTML(workspace.name)
-- 
GitLab