mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2025-01-04 06:18:49 +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>
|
<label class="label" for="id_cover">{% trans "Upload cover:" %}</label>
|
||||||
{{ form.cover }}
|
{{ form.cover }}
|
||||||
</div>
|
</div>
|
||||||
{% if book %}
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label class="label" for="id_cover_url">
|
<label class="label" for="id_cover_url">
|
||||||
{% trans "Load cover from url:" %}
|
{% trans "Load cover from url:" %}
|
||||||
</label>
|
</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>
|
</div>
|
||||||
{% endif %}
|
|
||||||
{% for error in form.cover.errors %}
|
{% for error in form.cover.errors %}
|
||||||
<p class="help is-danger">{{ error | escape }}</p>
|
<p class="help is-danger">{{ error | escape }}</p>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
|
@ -185,6 +185,8 @@ class EditBook(View):
|
||||||
data["confirm_mode"] = True
|
data["confirm_mode"] = True
|
||||||
# this isn't preserved because it isn't part of the form obj
|
# this isn't preserved because it isn't part of the form obj
|
||||||
data["remove_authors"] = request.POST.getlist("remove_authors")
|
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
|
# make sure the dates are passed in as datetime, they're currently a string
|
||||||
# QueryDicts are immutable, we need to copy
|
# QueryDicts are immutable, we need to copy
|
||||||
formcopy = data["form"].data.copy()
|
formcopy = data["form"].data.copy()
|
||||||
|
@ -261,12 +263,20 @@ class ConfirmEditBook(View):
|
||||||
work = models.Work.objects.create(title=form.cleaned_data["title"])
|
work = models.Work.objects.create(title=form.cleaned_data["title"])
|
||||||
work.authors.set(book.authors.all())
|
work.authors.set(book.authors.all())
|
||||||
book.parent_work = work
|
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"):
|
for author_id in request.POST.getlist("remove_authors"):
|
||||||
book.authors.remove(author_id)
|
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}")
|
return redirect(f"/book/{book.id}")
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue