From 5b50ecf922c5ef4b499e74f5566f0e76fde4702c Mon Sep 17 00:00:00 2001 From: loulous27 Date: Mon, 6 Apr 2026 10:10:42 +0200 Subject: [PATCH] Zip path correction + linters Formating --- photologue/views.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/photologue/views.py b/photologue/views.py index a3a6c27..e2b0793 100644 --- a/photologue/views.py +++ b/photologue/views.py @@ -7,6 +7,7 @@ import zipfile from io import BytesIO from pathlib import Path + from django.contrib import messages from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin from django.core.mail import mail_admins @@ -19,6 +20,7 @@ from django.utils.text import slugify from django.views.generic.dates import ArchiveIndexView, YearArchiveView from django.views.generic.detail import DetailView from django.views.generic.edit import DeleteView, FormView +from django.conf import settings from PIL import Image from django.contrib.auth import get_user_model @@ -163,9 +165,9 @@ class GalleryDetailView(LoginRequiredMixin, DetailView): if "owner" in self.kwargs: context["photos"] = context["photos"].filter(owner__id=self.kwargs["owner"]) - #Increment the photo view count + # Increment the photo view count - context["photos"].update(view_count=F('view_count') + 1) + context["photos"].update(view_count=F("view_count") + 1) return context @@ -181,10 +183,10 @@ class GalleryDownload(LoginRequiredMixin, DetailView): # Create zip file with pictures gallery = self.get_object() - gallery_year = Path("media/photos/"+str(+gallery.date_start.year)) - gallery_zip = gallery_year / (gallery.slug +".zip") + gallery_year = Path("/photos/" + str(+gallery.date_start.year)) + gallery_zip = gallery_year / (gallery.slug + ".zip") - with open(gallery_zip,"wb") as zip_bytes : + with open(settings.MEDIA_ROOT / gallery_zip, "wb") as zip_bytes: zip_file = zipfile.ZipFile(zip_bytes, "w") for photo in gallery.photos.filter(is_public=True): filename = os.path.basename(os.path.normpath(photo.image.path)) @@ -193,15 +195,16 @@ class GalleryDownload(LoginRequiredMixin, DetailView): # Return the path to it - return redirect("/"+str(gallery_zip).replace("\\","/")) #windows fix + return redirect( + settings.MEDIA_URL + str(gallery_zip).replace("\\", "/") + ) # windows fix # Return zip file - - #response = HttpResponse( + # response = HttpResponse( # byte_data.getvalue(), content_type="application/x-zip-compressed" - #) - #response["Content-Disposition"] = f"attachment; filename={gallery.slug}.zip" - #return response + # ) + # response["Content-Disposition"] = f"attachment; filename={gallery.slug}.zip" + # return response class GalleryUpload(PermissionRequiredMixin, FormView):