From 6d1d62cf2f388040fd618cacdcf30a79059a18b5 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 25 Feb 2022 11:50:25 -0800 Subject: [PATCH 01/11] View for starting to edit a book with existing data --- bookwyrm/views/books/edit_book.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/bookwyrm/views/books/edit_book.py b/bookwyrm/views/books/edit_book.py index 755c25b4..0b81acf8 100644 --- a/bookwyrm/views/books/edit_book.py +++ b/bookwyrm/views/books/edit_book.py @@ -9,6 +9,7 @@ from django.shortcuts import get_object_or_404, redirect from django.template.response import TemplateResponse from django.utils.datastructures import MultiValueDictKeyError from django.utils.decorators import method_decorator +from django.views.decorators.http import require_POST from django.views import View from bookwyrm import book_search, forms, models @@ -145,6 +146,15 @@ class EditBook(View): return redirect(f"/book/{book.id}") +@require_POST +@permission_required("bookwyrm.edit_book", raise_exception=True) +def create_book_from_data(request): + """create a book with starter data""" + data = {"form": forms.EditionForm(request.POST)} + return TemplateResponse(request, "book/edit/edit_book.html", data) + + + @method_decorator(login_required, name="dispatch") @method_decorator( permission_required("bookwyrm.edit_book", raise_exception=True), name="dispatch" From 1d99e455e83caac8804ff0a809d0002816b982b7 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 25 Feb 2022 16:40:21 -0800 Subject: [PATCH 02/11] Adds link to add edition to editions page --- .../templates/book/editions/editions.html | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/bookwyrm/templates/book/editions/editions.html b/bookwyrm/templates/book/editions/editions.html index a3ff0802..5d674d47 100644 --- a/bookwyrm/templates/book/editions/editions.html +++ b/bookwyrm/templates/book/editions/editions.html @@ -46,7 +46,25 @@ {% endfor %} -
+
{% include 'snippets/pagination.html' with page=editions path=request.path %}
+ +
+

+ {% trans "Can't find the edition you're looking for?" %} +

+ +
+ {% csrf_token %} + {{ work_form }} + +
+ +
+
+
+ {% endblock %} From c67f92af465fc12473bc9becbe3a4520c2efd346 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 25 Feb 2022 16:40:34 -0800 Subject: [PATCH 03/11] Add editions view --- bookwyrm/forms.py | 27 ++- bookwyrm/templates/book/edit/edit_book.html | 16 +- .../templates/book/edit/edit_book_form.html | 5 + bookwyrm/urls.py | 3 +- bookwyrm/views/__init__.py | 2 +- bookwyrm/views/books/edit_book.py | 217 ++++++++++++------ bookwyrm/views/books/editions.py | 3 +- 7 files changed, 196 insertions(+), 77 deletions(-) diff --git a/bookwyrm/forms.py b/bookwyrm/forms.py index 7ae4e446..9e694156 100644 --- a/bookwyrm/forms.py +++ b/bookwyrm/forms.py @@ -264,17 +264,40 @@ class FileLinkForm(CustomForm): ) +class EditionFromWorkForm(CustomForm): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + # make all fields hidden + for visible in self.visible_fields(): + visible.field.widget = forms.HiddenInput() + + class Meta: + model = models.Work + fields = [ + "title", + "subtitle", + "authors", + "description", + "languages", + "series", + "series_number", + "subjects", + "subject_places", + "cover", + "first_published_date", + ] + class EditionForm(CustomForm): class Meta: model = models.Edition exclude = [ + "authors", + "parent_work", "remote_id", "origin_id", "created_date", "updated_date", "edition_rank", - "authors", - "parent_work", "shelves", "connector", "search_vector", diff --git a/bookwyrm/templates/book/edit/edit_book.html b/bookwyrm/templates/book/edit/edit_book.html index 3d41058e..79ed1cc0 100644 --- a/bookwyrm/templates/book/edit/edit_book.html +++ b/bookwyrm/templates/book/edit/edit_book.html @@ -3,18 +3,24 @@ {% load humanize %} {% load utilities %} -{% block title %}{% if book %}{% blocktrans with book_title=book.title %}Edit "{{ book_title }}"{% endblocktrans %}{% else %}{% trans "Add Book" %}{% endif %}{% endblock %} +{% block title %} + {% if book.title %} + {% blocktrans with book_title=book.title %}Edit "{{ book_title }}"{% endblocktrans %} + {% else %} + {% trans "Add Book" %} + {% endif %} +{% endblock %} {% block content %}

- {% if book %} + {% if book.title %} {% blocktrans with book_title=book.title %}Edit "{{ book_title }}"{% endblocktrans %} {% else %} {% trans "Add Book" %} {% endif %}

- {% if book %} + {% if book.created_date %}
{% trans "Added:" %}
{{ book.created_date | naturaltime }}
@@ -33,7 +39,7 @@
- {% if book %} + {% if book.id %} {% trans "Cancel" %} {% else %} diff --git a/bookwyrm/templates/book/edit/edit_book_form.html b/bookwyrm/templates/book/edit/edit_book_form.html index fd2516a6..e2d7121f 100644 --- a/bookwyrm/templates/book/edit/edit_book_form.html +++ b/bookwyrm/templates/book/edit/edit_book_form.html @@ -9,6 +9,8 @@ {% csrf_token %} + +
@@ -123,8 +125,11 @@
{% if book.authors.exists %} + {# preserve authors if the book is unsaved #} + {{ form.authors.as_hidden }}
{% for author in book.authors.all %} + {{ form.authors.as_hidden }}
{% if book.authors.exists %} {# preserve authors if the book is unsaved #} - {{ form.authors.as_hidden }} +
{% for author in book.authors.all %} - {{ form.authors.as_hidden }}
{% endfor %} -
From 26f0501e2f756fd475bee5081c881527b88af0ff Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 17 Mar 2022 07:40:55 -0700 Subject: [PATCH 09/11] SHow editions link on all book pages --- bookwyrm/templates/book/book.html | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/bookwyrm/templates/book/book.html b/bookwyrm/templates/book/book.html index fa098281..453480f9 100644 --- a/bookwyrm/templates/book/book.html +++ b/bookwyrm/templates/book/book.html @@ -208,9 +208,17 @@ {% endif %} - {% if book.parent_work.editions.count > 1 %} -

{% blocktrans with path=book.parent_work.local_path count=book.parent_work.editions.count %}{{ count }} editions{% endblocktrans %}

- {% endif %} + {% with work=book.parent_work %} +

+ + {% blocktrans trimmed count counter=work.editions.count with count=work.editions.count|intcomma %} + {{ count }} edition + {% plural %} + {{ count }} editions + {% endblocktrans %} + +

+ {% endwith %}
{# user's relationship to the book #} From a684d86d15f5f1715ab49d6f9228ada016aaaf40 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 17 Mar 2022 08:02:59 -0700 Subject: [PATCH 10/11] Fixes subjects in add edition view --- bookwyrm/forms/books.py | 1 - bookwyrm/templates/book/editions/editions.html | 13 ++++++++++++- bookwyrm/views/books/edit_book.py | 1 + 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/bookwyrm/forms/books.py b/bookwyrm/forms/books.py index 20f307fa..d96ad067 100644 --- a/bookwyrm/forms/books.py +++ b/bookwyrm/forms/books.py @@ -86,7 +86,6 @@ class EditionForm(CustomForm): "ASIN": forms.TextInput(attrs={"aria-describedby": "desc_ASIN"}), } - class EditionFromWorkForm(CustomForm): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) diff --git a/bookwyrm/templates/book/editions/editions.html b/bookwyrm/templates/book/editions/editions.html index 5d674d47..e15e7a74 100644 --- a/bookwyrm/templates/book/editions/editions.html +++ b/bookwyrm/templates/book/editions/editions.html @@ -57,7 +57,18 @@ {% csrf_token %} - {{ work_form }} + {{ work_form.title }} + {{ work_form.subtitle }} + {{ work_form.authors }} + {{ work_form.description }} + {{ work_form.languages }} + {{ work_form.series }} + {{ work_form.cover }} + {{ work_form.first_published_date }} + {% for subject in work.subjects %} + + {% endfor %} +