mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-15 02:33:13 +00:00
Give error if image file doesn't exist
This commit is contained in:
parent
297240ce45
commit
4c85c39a78
1 changed files with 14 additions and 0 deletions
|
|
@ -1,3 +1,4 @@
|
|||
import os
|
||||
import json
|
||||
|
||||
from django.shortcuts import render, redirect, get_object_or_404
|
||||
|
|
@ -118,6 +119,19 @@ def edit(request, image_id):
|
|||
except NoReverseMatch:
|
||||
url_generator_enabled = False
|
||||
|
||||
try:
|
||||
local_path = image.file.path
|
||||
except NotImplementedError:
|
||||
# Image is hosted externally (eg, S3)
|
||||
local_path = None
|
||||
|
||||
if local_path:
|
||||
# Give error if image file doesn't exist
|
||||
if not os.path.isfile(local_path):
|
||||
messages.error(request, _("The source image file could not be found. Please change the source or delete the image.").format(image.title), buttons=[
|
||||
messages.button(reverse('wagtailimages_delete_image', args=(image.id,)), _('Delete'))
|
||||
])
|
||||
|
||||
return render(request, "wagtailimages/images/edit.html", {
|
||||
'image': image,
|
||||
'form': form,
|
||||
|
|
|
|||
Loading…
Reference in a new issue