Paginate user’s maps combined downloads

This commit is contained in:
David Larlet 2023-12-08 16:37:07 -05:00
parent 5476cbee0f
commit 46cf432eb4
No known key found for this signature in database
GPG key ID: 3E2953A359E7E7BD
3 changed files with 15 additions and 6 deletions

View file

@ -331,7 +331,7 @@ table.maps .button {
margin-bottom: 2px;
padding:4px 6px;
height: 36px;
line-height: 23px;
line-height: 26px;
}
/* **************************** */

View file

@ -45,9 +45,9 @@
</tbody>
<tfoot>
<tr>
<td colspan="5"></td>
<td>
<a href="{% url 'user_download' %}" class="button">{% translate "Download all maps" %}</a>
<td colspan="4"></td>
<td colspan="2">
<a href="{% url 'user_download' %}?p={{ request.GET.p }}" class="button">{% translate "Download all these maps" %}</a>
</td>
</tr>
</tfoot>

View file

@ -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")