From c67f92af465fc12473bc9becbe3a4520c2efd346 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 25 Feb 2022 16:40:34 -0800 Subject: [PATCH] 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 7ae4e446f..9e6941569 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 3d41058e3..79ed1cc0d 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 fd2516a66..e2d7121ff 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 }}