From 4e55018e415cb8aab065eded438031da424db1c6 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 18 Mar 2021 09:37:16 -0700 Subject: [PATCH 1/5] Moves book templates into dir --- bookwyrm/templates/{ => book}/book.html | 4 ++-- bookwyrm/templates/{ => book}/edit_book.html | 0 bookwyrm/urls.py | 2 +- bookwyrm/views/books.py | 10 +++++----- 4 files changed, 8 insertions(+), 8 deletions(-) rename bookwyrm/templates/{ => book}/book.html (98%) rename bookwyrm/templates/{ => book}/edit_book.html (100%) diff --git a/bookwyrm/templates/book.html b/bookwyrm/templates/book/book.html similarity index 98% rename from bookwyrm/templates/book.html rename to bookwyrm/templates/book/book.html index b9708451d..adc40e481 100644 --- a/bookwyrm/templates/book.html +++ b/bookwyrm/templates/book/book.html @@ -43,10 +43,10 @@ {% if request.user.is_authenticated and not book.cover %}

{% trans "Add cover" %}

-
+ {% csrf_token %}
diff --git a/bookwyrm/templates/edit_book.html b/bookwyrm/templates/book/edit_book.html similarity index 100% rename from bookwyrm/templates/edit_book.html rename to bookwyrm/templates/book/edit_book.html diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index 688c8a777..fca645abf 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -152,7 +152,7 @@ urlpatterns = [ re_path(r"^create-book/?$", views.EditBook.as_view()), re_path(r"^create-book/confirm?$", views.ConfirmEditBook.as_view()), re_path(r"%s/editions(.json)?/?$" % book_path, views.Editions.as_view()), - re_path(r"^upload-cover/(?P\d+)/?$", views.upload_cover), + re_path(r"^upload-cover/(?P\d+)/?$", views.upload_cover, name="upload-cover"), re_path(r"^add-description/(?P\d+)/?$", views.add_description), re_path(r"^resolve-book/?$", views.resolve_book), re_path(r"^switch-edition/?$", views.switch_edition), diff --git a/bookwyrm/views/books.py b/bookwyrm/views/books.py index 0b23b0d63..00f3bc54d 100644 --- a/bookwyrm/views/books.py +++ b/bookwyrm/views/books.py @@ -97,7 +97,7 @@ class Book(View): "readthroughs": readthroughs, "path": "/book/%s" % book_id, } - return TemplateResponse(request, "book.html", data) + return TemplateResponse(request, "book/book.html", data) @method_decorator(login_required, name="dispatch") @@ -115,7 +115,7 @@ class EditBook(View): if not book.description: book.description = book.parent_work.description data = {"book": book, "form": forms.EditionForm(instance=book)} - return TemplateResponse(request, "edit_book.html", data) + return TemplateResponse(request, "book/edit_book.html", data) def post(self, request, book_id=None): """ edit a book cool """ @@ -125,7 +125,7 @@ class EditBook(View): data = {"book": book, "form": form} if not form.is_valid(): - return TemplateResponse(request, "edit_book.html", data) + return TemplateResponse(request, "book/edit_book.html", data) add_author = request.POST.get("add_author") # we're adding an author through a free text field @@ -169,7 +169,7 @@ 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") - return TemplateResponse(request, "edit_book.html", data) + return TemplateResponse(request, "book/edit_book.html", data) remove_authors = request.POST.getlist("remove_authors") for author_id in remove_authors: @@ -194,7 +194,7 @@ class ConfirmEditBook(View): data = {"book": book, "form": form} if not form.is_valid(): - return TemplateResponse(request, "edit_book.html", data) + return TemplateResponse(request, "book/edit_book.html", data) with transaction.atomic(): # save book From ae6d8529af7ff1ad952b0088576347350943cb58 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 18 Mar 2021 09:44:59 -0700 Subject: [PATCH 2/5] Moves add cover into modal --- bookwyrm/templates/book/book.html | 13 ++++-------- bookwyrm/templates/book/cover_modal.html | 26 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 9 deletions(-) create mode 100644 bookwyrm/templates/book/cover_modal.html diff --git a/bookwyrm/templates/book/book.html b/bookwyrm/templates/book/book.html index adc40e481..0d908110b 100644 --- a/bookwyrm/templates/book/book.html +++ b/bookwyrm/templates/book/book.html @@ -41,15 +41,10 @@ {% include 'snippets/shelve_button/shelve_button.html' %} {% if request.user.is_authenticated and not book.cover %} -
-

{% trans "Add cover" %}

-
- {% csrf_token %} - - -
+
+ {% 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 'book/cover_modal.html' with book=book controls_text="add-cover" controls_uid=book.id %}
{% endif %} diff --git a/bookwyrm/templates/book/cover_modal.html b/bookwyrm/templates/book/cover_modal.html new file mode 100644 index 000000000..b82c441f7 --- /dev/null +++ b/bookwyrm/templates/book/cover_modal.html @@ -0,0 +1,26 @@ +{% extends 'components/modal.html' %} +{% load i18n %} + +{% block modal-title %} +{% trans "Add cover" %} +{% endblock %} + +{% block modal-form-open %} +
+{% endblock %} + +{% block modal-body %} + +{% endblock %} + +{% block modal-footer %} + +{% endblock %} +{% block modal-form-close %}
{% endblock %} + From 9470b2831f0e364dd961ca82806637e9abbc83b1 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 18 Mar 2021 10:03:53 -0700 Subject: [PATCH 3/5] Add cover via url --- bookwyrm/templates/book/cover_modal.html | 18 ++++++++++++++---- bookwyrm/urls.py | 4 +++- bookwyrm/views/books.py | 15 +++++++++++++++ 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/bookwyrm/templates/book/cover_modal.html b/bookwyrm/templates/book/cover_modal.html index b82c441f7..f09b44951 100644 --- a/bookwyrm/templates/book/cover_modal.html +++ b/bookwyrm/templates/book/cover_modal.html @@ -10,17 +10,27 @@ {% endblock %} {% block modal-body %} -