From 46cf432eb4eeeff7ba3b68c7ea5f4a89b980a6a4 Mon Sep 17 00:00:00 2001 From: David Larlet Date: Fri, 8 Dec 2023 16:37:07 -0500 Subject: [PATCH] =?UTF-8?q?Paginate=20user=E2=80=99s=20maps=20combined=20d?= =?UTF-8?q?ownloads?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- umap/static/umap/content.css | 2 +- umap/templates/umap/map_table.html | 6 +++--- umap/views.py | 13 +++++++++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/umap/static/umap/content.css b/umap/static/umap/content.css index 55fb1c98..3d7a8c2e 100644 --- a/umap/static/umap/content.css +++ b/umap/static/umap/content.css @@ -331,7 +331,7 @@ table.maps .button { margin-bottom: 2px; padding:4px 6px; height: 36px; - line-height: 23px; + line-height: 26px; } /* **************************** */ diff --git a/umap/templates/umap/map_table.html b/umap/templates/umap/map_table.html index 4cd2b12b..84b8c12b 100644 --- a/umap/templates/umap/map_table.html +++ b/umap/templates/umap/map_table.html @@ -45,9 +45,9 @@ - - - {% translate "Download all maps" %} + + + {% translate "Download all these maps" %} diff --git a/umap/views.py b/umap/views.py index 00695b47..423308d5 100644 --- a/umap/views.py +++ b/umap/views.py @@ -307,6 +307,15 @@ user_dashboard = UserDashboard.as_view() class UserDownload(PaginatorMixin, DetailView, SearchMixin): model = User + def is_owner(self): + return self.request.user == self.object + + @property + def per_page(self): + if self.is_owner(): + return settings.UMAP_MAPS_PER_PAGE_OWNER + return settings.UMAP_MAPS_PER_PAGE + def get_object(self): return self.get_queryset().get(pk=self.request.user.pk) @@ -318,10 +327,10 @@ class UserDownload(PaginatorMixin, DetailView, SearchMixin): def render_to_response(self, context, *args, **kwargs): zip_buffer = io.BytesIO() with zipfile.ZipFile(zip_buffer, "a", zipfile.ZIP_DEFLATED, False) as zip_file: - for map_ in self.get_maps(): + for map_ in self.paginate(self.get_maps()): map_geojson = map_.generate_geojson(self.request) geojson_file = io.StringIO(json.dumps(map_geojson)) - file_name = f"umap_backup_{map_.slug}.umap" + file_name = f"umap_backup_{map_.slug}_{map_.pk}.umap" zip_file.writestr(file_name, geojson_file.getvalue()) response = HttpResponse(zip_buffer.getvalue(), content_type="application/zip")