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 io import BytesIO
from pathlib import Path from pathlib import Path
from django.contrib import messages from django.contrib import messages
from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin
from django.core.mail import mail_admins 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.dates import ArchiveIndexView, YearArchiveView
from django.views.generic.detail import DetailView from django.views.generic.detail import DetailView
from django.views.generic.edit import DeleteView, FormView from django.views.generic.edit import DeleteView, FormView
from django.conf import settings
from PIL import Image from PIL import Image
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
@ -163,9 +165,9 @@ class GalleryDetailView(LoginRequiredMixin, DetailView):
if "owner" in self.kwargs: if "owner" in self.kwargs:
context["photos"] = context["photos"].filter(owner__id=self.kwargs["owner"]) 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 return context
@ -181,10 +183,10 @@ class GalleryDownload(LoginRequiredMixin, DetailView):
# Create zip file with pictures # Create zip file with pictures
gallery = self.get_object() 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") 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") zip_file = zipfile.ZipFile(zip_bytes, "w")
for photo in gallery.photos.filter(is_public=True): for photo in gallery.photos.filter(is_public=True):
filename = os.path.basename(os.path.normpath(photo.image.path)) filename = os.path.basename(os.path.normpath(photo.image.path))
@ -193,15 +195,16 @@ class GalleryDownload(LoginRequiredMixin, DetailView):
# Return the path to it # 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 # Return zip file
# response = HttpResponse(
#response = HttpResponse(
# byte_data.getvalue(), content_type="application/x-zip-compressed" # byte_data.getvalue(), content_type="application/x-zip-compressed"
#) # )
#response["Content-Disposition"] = f"attachment; filename={gallery.slug}.zip" # response["Content-Disposition"] = f"attachment; filename={gallery.slug}.zip"
#return response # return response
class GalleryUpload(PermissionRequiredMixin, FormView): class GalleryUpload(PermissionRequiredMixin, FormView):