forked from mirrors/bookwyrm
Merge pull request #840 from mouse-reeve/cover-error-messaging
Adds error messaging for invalid cover urls
This commit is contained in:
commit
91955987ad
2 changed files with 8 additions and 4 deletions
|
@ -49,6 +49,9 @@
|
||||||
{% trans "Add cover" as button_text %}
|
{% trans "Add cover" as button_text %}
|
||||||
{% include 'snippets/toggle/toggle_button.html' with text=button_text controls_text="add-cover" controls_uid=book.id focus="modal-title-add-cover" class="is-small" %}
|
{% include 'snippets/toggle/toggle_button.html' with text=button_text controls_text="add-cover" controls_uid=book.id focus="modal-title-add-cover" class="is-small" %}
|
||||||
{% include 'book/cover_modal.html' with book=book controls_text="add-cover" controls_uid=book.id %}
|
{% include 'book/cover_modal.html' with book=book controls_text="add-cover" controls_uid=book.id %}
|
||||||
|
{% if request.GET.cover_error %}
|
||||||
|
<p class="help is-danger">{% trans "Failed to load cover" %}</p>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
|
@ -289,18 +289,19 @@ def upload_cover(request, book_id):
|
||||||
url = request.POST.get("cover-url")
|
url = request.POST.get("cover-url")
|
||||||
if url:
|
if url:
|
||||||
image = set_cover_from_url(url)
|
image = set_cover_from_url(url)
|
||||||
|
if image:
|
||||||
book.cover.save(*image)
|
book.cover.save(*image)
|
||||||
|
|
||||||
return redirect("/book/%d" % book.id)
|
return redirect("{:s}?cover_error=True".format(book.local_path))
|
||||||
|
|
||||||
form = forms.CoverForm(request.POST, request.FILES, instance=book)
|
form = forms.CoverForm(request.POST, request.FILES, instance=book)
|
||||||
if not form.is_valid() or not form.files.get("cover"):
|
if not form.is_valid() or not form.files.get("cover"):
|
||||||
return redirect("/book/%d" % book.id)
|
return redirect(book.local_path)
|
||||||
|
|
||||||
book.cover = form.files["cover"]
|
book.cover = form.files["cover"]
|
||||||
book.save()
|
book.save()
|
||||||
|
|
||||||
return redirect("/book/%s" % book.id)
|
return redirect(book.local_path)
|
||||||
|
|
||||||
|
|
||||||
def set_cover_from_url(url):
|
def set_cover_from_url(url):
|
||||||
|
|
Loading…
Reference in a new issue