From 5476cbee0fe867bb756fe9aeddfdec22b481e738 Mon Sep 17 00:00:00 2001 From: David Larlet Date: Fri, 24 Nov 2023 17:04:47 -0500 Subject: [PATCH 1/8] =?UTF-8?q?Ability=20to=20download=20all=20maps=20from?= =?UTF-8?q?=20user=E2=80=99s=20dashboard?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- umap/models.py | 15 ++++++++++ umap/templates/umap/map_table.html | 8 ++++++ umap/urls.py | 13 ++------- umap/views.py | 44 ++++++++++++++++++++++-------- 4 files changed, 59 insertions(+), 21 deletions(-) diff --git a/umap/models.py b/umap/models.py index f8c31238..9b868bba 100644 --- a/umap/models.py +++ b/umap/models.py @@ -1,3 +1,4 @@ +import json import os import time @@ -222,6 +223,20 @@ class Map(NamedModel): ) return map_settings + def generate_geojson(self, request): + geojson = self.settings + geojson["type"] = "umap" + geojson["uri"] = request.build_absolute_uri(self.get_absolute_url()) + datalayers = [] + for datalayer in self.datalayer_set.all(): + with open(datalayer.geojson.path, "rb") as f: + layer = json.loads(f.read()) + if datalayer.settings: + layer["_umap_options"] = datalayer.settings + datalayers.append(layer) + geojson["layers"] = datalayers + return geojson + def get_absolute_url(self): return reverse("map", kwargs={"slug": self.slug or "map", "map_id": self.pk}) diff --git a/umap/templates/umap/map_table.html b/umap/templates/umap/map_table.html index 8007598b..4cd2b12b 100644 --- a/umap/templates/umap/map_table.html +++ b/umap/templates/umap/map_table.html @@ -43,6 +43,14 @@ {% endwith %} {% endfor %} + + + + + {% translate "Download all maps" %} + + +