mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-29 19:40:32 +00:00
Allow adding a cover by url when adding a new book (#1443)
This commit is contained in:
parent
cfca806af8
commit
0e6895633c
2 changed files with 13 additions and 5 deletions
|
@ -236,14 +236,12 @@
|
|||
<label class="label" for="id_cover">{% trans "Upload cover:" %}</label>
|
||||
{{ form.cover }}
|
||||
</div>
|
||||
{% if book %}
|
||||
<div class="field">
|
||||
<label class="label" for="id_cover_url">
|
||||
{% trans "Load cover from url:" %}
|
||||
</label>
|
||||
<input class="input" name="cover-url" id="id_cover_url">
|
||||
<input class="input" name="cover-url" id="id_cover_url" type="url" value="{{ cover_url|default:'' }}">
|
||||
</div>
|
||||
{% endif %}
|
||||
{% for error in form.cover.errors %}
|
||||
<p class="help is-danger">{{ error | escape }}</p>
|
||||
{% endfor %}
|
||||
|
|
|
@ -185,6 +185,8 @@ class EditBook(View):
|
|||
data["confirm_mode"] = True
|
||||
# this isn't preserved because it isn't part of the form obj
|
||||
data["remove_authors"] = request.POST.getlist("remove_authors")
|
||||
data["cover_url"] = request.POST.get("cover-url")
|
||||
|
||||
# make sure the dates are passed in as datetime, they're currently a string
|
||||
# QueryDicts are immutable, we need to copy
|
||||
formcopy = data["form"].data.copy()
|
||||
|
@ -261,12 +263,20 @@ class ConfirmEditBook(View):
|
|||
work = models.Work.objects.create(title=form.cleaned_data["title"])
|
||||
work.authors.set(book.authors.all())
|
||||
book.parent_work = work
|
||||
# we don't tell the world when creating a book
|
||||
book.save(broadcast=False)
|
||||
|
||||
for author_id in request.POST.getlist("remove_authors"):
|
||||
book.authors.remove(author_id)
|
||||
|
||||
# import cover, if requested
|
||||
url = request.POST.get("cover-url")
|
||||
if url:
|
||||
image = set_cover_from_url(url)
|
||||
if image:
|
||||
book.cover.save(*image, save=False)
|
||||
|
||||
# we don't tell the world when creating a book
|
||||
book.save(broadcast=False)
|
||||
|
||||
return redirect(f"/book/{book.id}")
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue