Test image using Pillow
This commit is contained in:
parent
baf70d396c
commit
59ac6535af
1 changed files with 12 additions and 0 deletions
|
|
@ -17,6 +17,7 @@ from django.views.generic.edit import FormView
|
|||
from photologue.models import Gallery, Photo
|
||||
from photologue.views import GalleryArchiveIndexView, GalleryYearArchiveView
|
||||
from taggit.models import Tag
|
||||
from PIL import Image
|
||||
|
||||
from .forms import UploadForm
|
||||
from .models import PhotoExtended
|
||||
|
|
@ -115,6 +116,17 @@ class GalleryUpload(FormView):
|
|||
gallery = form.get_or_create_gallery()
|
||||
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()
|
||||
except Exception:
|
||||
# Pillow doesn't recognize it as an image, skip it
|
||||
messages.error(self.request, f"{photo_file.name} was not recognized as an image")
|
||||
failed_upload += 1
|
||||
continue
|
||||
|
||||
title = f"{gallery.title} - {photo_file.name}"
|
||||
try:
|
||||
photo = Photo(title=title, slug=slugify(title))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue