Skip to content

Commit

Permalink
Merge pull request #1973 from bookwyrm-social/add-edition
Browse files Browse the repository at this point in the history
Create another edition for existing work
  • Loading branch information
mouse-reeve authored Mar 17, 2022
2 parents ef4e06a + 0101d25 commit 2047365
Show file tree
Hide file tree
Showing 10 changed files with 270 additions and 102 deletions.
24 changes: 24 additions & 0 deletions bookwyrm/forms/books.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,27 @@ class Meta:
),
"ASIN": forms.TextInput(attrs={"aria-describedby": "desc_ASIN"}),
}


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",
]
14 changes: 11 additions & 3 deletions bookwyrm/templates/book/book.html
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,17 @@ <h1 class="title" itemprop="name">
{% endif %}


{% if book.parent_work.editions.count > 1 %}
<p>{% blocktrans with path=book.parent_work.local_path count=book.parent_work.editions.count %}<a href="{{ path }}/editions">{{ count }} editions</a>{% endblocktrans %}</p>
{% endif %}
{% with work=book.parent_work %}
<p>
<a href="{{ work.local_path }}/editions">
{% blocktrans trimmed count counter=work.editions.count with count=work.editions.count|intcomma %}
{{ count }} edition
{% plural %}
{{ count }} editions
{% endblocktrans %}
</a>
</p>
{% endwith %}
</div>

{# user's relationship to the book #}
Expand Down
18 changes: 12 additions & 6 deletions bookwyrm/templates/book/edit/edit_book.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
<header class="block">
<h1 class="title level-left">
{% if book %}
{% if book.title %}
{% blocktrans with book_title=book.title %}Edit "{{ book_title }}"{% endblocktrans %}
{% else %}
{% trans "Add Book" %}
{% endif %}
</h1>
{% if book %}
{% if book.created_date %}
<dl>
<dt class="is-pulled-left mr-5 has-text-weight-semibold">{% trans "Added:" %}</dt>
<dd class="ml-2">{{ book.created_date | naturaltime }}</dd>
Expand All @@ -33,7 +39,7 @@ <h1 class="title level-left">

<form
class="block"
{% if book %}
{% if book.id %}
name="edit-book"
action="{{ book.local_path }}/{% if confirm_mode %}confirm{% else %}edit{% endif %}"
{% else %}
Expand Down Expand Up @@ -97,7 +103,7 @@ <h2 class="title is-4">{% trans "Confirm Book Info" %}</h2>
<input type="radio" name="parent_work" value="{{ match.parent_work.id }}"> {{ match.parent_work.title }}
</label>
{% endfor %}
<label>
<label class="label mt-2">
<input type="radio" name="parent_work" value="0" required> {% trans "This is a new work" %}
</label>
</fieldset>
Expand All @@ -119,7 +125,7 @@ <h2 class="title is-4">{% trans "Confirm Book Info" %}</h2>
{% if not confirm_mode %}
<div class="block">
<button class="button is-primary" type="submit">{% trans "Save" %}</button>
{% if book %}
{% if book.id %}
<a class="button" href="{{ book.local_path }}">{% trans "Cancel" %}</a>
{% else %}
<a href="/" class="button" data-back>
Expand Down
4 changes: 4 additions & 0 deletions bookwyrm/templates/book/edit/edit_book_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
{% csrf_token %}

<input type="hidden" name="last_edited_by" value="{{ request.user.id }}">
<input type="hidden" name="parent_work" value="{% firstof book.parent_work.id form.parent_work %}">

<div class="columns">
<div class="column is-half">
<section class="block">
Expand Down Expand Up @@ -175,6 +177,8 @@ <h2 class="title is-4">
</h2>
<div class="box">
{% if book.authors.exists %}
{# preserve authors if the book is unsaved #}
<input type="hidden" name="authors" value="{% for author in book.authors %}{{ author.id }},{% endfor %}">
<fieldset>
{% for author in book.authors.all %}
<div class="is-flex is-justify-content-space-between">
Expand Down
31 changes: 30 additions & 1 deletion bookwyrm/templates/book/editions/editions.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,36 @@ <h2 class="title is-5 mb-1">
{% endfor %}
</div>

<div>
<div class="block">
{% include 'snippets/pagination.html' with page=editions path=request.path %}
</div>

<div class="block has-text-centered help">
<p>
{% trans "Can't find the edition you're looking for?" %}
</p>

<form action="{% url 'create-book-data' %}" method="POST" name="add-edition-form">
{% csrf_token %}
{{ 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 %}
<input type="hidden" name="subjects" value="{{ subject }}">
{% endfor %}

<input type="hidden" name="parent_work" value="{{ work.id }}">
<div>
<button class="button is-small" type="submit">
{% trans "Add another edition" %}
</button>
</div>
</form>
</div>

{% endblock %}
2 changes: 1 addition & 1 deletion bookwyrm/tests/views/books/test_edit_book.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_edit_book_page(self):

def test_edit_book_create_page(self):
"""there are so many views, this just makes sure it LOADS"""
view = views.EditBook.as_view()
view = views.CreateBook.as_view()
request = self.factory.get("")
request.user = self.local_user
request.user.is_superuser = True
Expand Down
5 changes: 4 additions & 1 deletion bookwyrm/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,10 @@
),
re_path(rf"{BOOK_PATH}/edit/?$", views.EditBook.as_view(), name="edit-book"),
re_path(rf"{BOOK_PATH}/confirm/?$", views.ConfirmEditBook.as_view()),
re_path(r"^create-book/?$", views.EditBook.as_view(), name="create-book"),
re_path(
r"^create-book/data/?$", views.create_book_from_data, name="create-book-data"
),
re_path(r"^create-book/?$", views.CreateBook.as_view(), name="create-book"),
re_path(r"^create-book/confirm/?$", views.ConfirmEditBook.as_view()),
re_path(rf"{BOOK_PATH}/editions(.json)?/?$", views.Editions.as_view()),
re_path(
Expand Down
7 changes: 6 additions & 1 deletion bookwyrm/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@
resolve_book,
)
from .books.books import update_book_from_remote
from .books.edit_book import EditBook, ConfirmEditBook
from .books.edit_book import (
EditBook,
ConfirmEditBook,
CreateBook,
create_book_from_data,
)
from .books.editions import Editions, switch_edition
from .books.links import BookFileLinks, AddFileLink, delete_link

Expand Down
Loading

0 comments on commit 2047365

Please sign in to comment.