Zip path correction + linters Formating
This commit is contained in:
parent
1b465aa903
commit
5b50ecf922
1 changed files with 14 additions and 11 deletions
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue