diff --git a/photo21/settings.py b/photo21/settings.py index 7f8299a7abfe94282edf3adafa69d16a01af057f..62eb8ec2432570928fc88482dd6b6912f6a6a606 100644 --- a/photo21/settings.py +++ b/photo21/settings.py @@ -236,3 +236,4 @@ CRISPY_TEMPLATE_PACK = 'bootstrap4' # Photologue PHOTOLOGUE_GALLERY_SAMPLE_SIZE = 1 +PHOTOLOGUE_DIR = '.' diff --git a/photologue_custom/views.py b/photologue_custom/views.py index 81df13dfc723a9dbbd73e1775b0dd7e45e9362d4..04bfa69cdb15077a976760b4cb804922886ade91 100644 --- a/photologue_custom/views.py +++ b/photologue_custom/views.py @@ -4,6 +4,7 @@ import os import zipfile from io import BytesIO +from pathlib import Path from django.contrib import messages from django.contrib.auth.mixins import (LoginRequiredMixin, @@ -121,10 +122,11 @@ class GalleryUpload(PermissionRequiredMixin, FormView): # We take files from the request to support multiple upload files = self.request.FILES.getlist('file_field') gallery = form.get_or_create_gallery() + gallery_year = Path(str(gallery.extended.date_start.year)) + gallery_dir = gallery_year / gallery.slug failed_upload = 0 for photo_file in files: # Check that we have a valid image - print(photo_file, type(photo_file)) try: opened = Image.open(photo_file) opened.verify() @@ -137,7 +139,8 @@ class GalleryUpload(PermissionRequiredMixin, FormView): title = f"{gallery.title} - {photo_file.name}" try: photo = Photo(title=title, slug=slugify(title)) - photo.image.save(photo_file.name, photo_file) + photo_name = str(gallery_dir / photo_file.name) + photo.image.save(photo_name, photo_file) photo.save() photo.galleries.set([gallery]) PhotoExtended.objects.create(photo=photo, owner=self.request.user)