Zip path correction + linters Formating

This commit is contained in:
loulous27 2026-04-06 10:10:42 +02:00
parent 1b465aa903
commit 5b50ecf922

View file

@ -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
@ -165,7 +167,7 @@ class GalleryDetailView(LoginRequiredMixin, DetailView):
# 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_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,10 +195,11 @@ 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(
# byte_data.getvalue(), content_type="application/x-zip-compressed"
# )