From 25dee8362d013eb4398ee22730d9a64f4b8a769a Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Tue, 22 Dec 2020 09:26:40 -0800 Subject: [PATCH] Adds edit author form and stores last edited by --- bookwyrm/forms.py | 13 ++++- bookwyrm/outgoing.py | 4 +- bookwyrm/templates/author.html | 22 ++++++- bookwyrm/templates/edit_author.html | 89 +++++++++++++++++++++++++++++ bookwyrm/templates/edit_book.html | 36 ++++++------ bookwyrm/urls.py | 2 + bookwyrm/view_actions.py | 27 ++++++++- bookwyrm/views.py | 14 +++++ 8 files changed, 182 insertions(+), 25 deletions(-) create mode 100644 bookwyrm/templates/edit_author.html diff --git a/bookwyrm/forms.py b/bookwyrm/forms.py index c4a602ca..686ac8b1 100644 --- a/bookwyrm/forms.py +++ b/bookwyrm/forms.py @@ -30,6 +30,7 @@ class CustomForm(ModelForm): visible.field.widget.attrs['rows'] = None visible.field.widget.attrs['class'] = css_classes[input_type] + # pylint: disable=missing-class-docstring class LoginForm(CustomForm): class Meta: @@ -121,13 +122,13 @@ class EditionForm(CustomForm): model = models.Edition exclude = [ 'remote_id', + 'origin_id', 'created_date', 'updated_date', 'authors',# TODO 'parent_work', 'shelves', - 'misc_identifiers', 'subjects',# TODO 'subject_places',# TODO @@ -135,6 +136,16 @@ class EditionForm(CustomForm): 'connector', ] +class AuthorForm(CustomForm): + class Meta: + model = models.Author + exclude = [ + 'remote_id', + 'origin_id', + 'created_date', + 'updated_date', + ] + class ImportForm(forms.Form): csv_file = forms.FileField() diff --git a/bookwyrm/outgoing.py b/bookwyrm/outgoing.py index 13df9026..00154cf4 100644 --- a/bookwyrm/outgoing.py +++ b/bookwyrm/outgoing.py @@ -375,9 +375,9 @@ def handle_unboost(user, status): broadcast(user, activity) -def handle_update_book(user, book): +def handle_update_book_data(user, item): ''' broadcast the news about our book ''' - broadcast(user, book.to_update_activity(user)) + broadcast(user, item.to_update_activity(user)) def handle_update_user(user): diff --git a/bookwyrm/templates/author.html b/bookwyrm/templates/author.html index 9a7a20ab..5e8aab71 100644 --- a/bookwyrm/templates/author.html +++ b/bookwyrm/templates/author.html @@ -2,13 +2,31 @@ {% load bookwyrm_tags %} {% block content %}
-

{{ author.name }}

+
+
+

{{ author.name }}

+
+ {% if request.user.is_authenticated and perms.bookwyrm.edit_book %} + + {% endif %} +
+
+
{% if author.bio %}

- {{ author.bio }} + {{ author.bio | to_markdown | safe }}

{% endif %} + {% if author.wikipedia_link %} +

Wikipedia

+ {% endif %}
diff --git a/bookwyrm/templates/edit_author.html b/bookwyrm/templates/edit_author.html new file mode 100644 index 00000000..b08aa983 --- /dev/null +++ b/bookwyrm/templates/edit_author.html @@ -0,0 +1,89 @@ +{% extends 'layout.html' %} +{% load humanize %} +{% block content %} +
+
+

+ Edit "{{ author.name }}" +

+ +
+
+

Added: {{ author.created_date | naturaltime }}

+

Updated: {{ author.updated_date | naturaltime }}

+

Last edited by: {{ author.last_edited_by.display_name }}

+
+
+ +{% if form.non_field_errors %} +
+

{{ form.non_field_errors }}

+
+{% endif %} + +
+ {% csrf_token %} + + +
+
+

Metadata

+

{{ form.name }}

+ {% for error in form.name.errors %} +

{{ error | escape }}

+ {% endfor %} + +

{{ form.bio }}

+ {% for error in form.bio.errors %} +

{{ error | escape }}

+ {% endfor %} + +

{{ form.wikipedia_link }}

+ {% for error in form.wikipedia_link.errors %} +

{{ error | escape }}

+ {% endfor %} + +

{{ form.born }}

+ {% for error in form.born.errors %} +

{{ error | escape }}

+ {% endfor %} + +

{{ form.died }}

+ {% for error in form.died.errors %} +

{{ error | escape }}

+ {% endfor %} +
+
+

Author Identifiers

+

{{ form.openlibrary_key }}

+ {% for error in form.openlibrary_key.errors %} +

{{ error | escape }}

+ {% endfor %} + +

{{ form.librarything_key }}

+ {% for error in form.librarything_key.errors %} +

{{ error | escape }}

+ {% endfor %} + +

{{ form.goodreads_key }}

+ {% for error in form.goodreads_key.errors %} +

{{ error | escape }}

+ {% endfor %} + +
+
+ +
+ + Cancel +
+
+ +{% endblock %} + diff --git a/bookwyrm/templates/edit_book.html b/bookwyrm/templates/edit_book.html index 3d63ae6d..b730f3e4 100644 --- a/bookwyrm/templates/edit_book.html +++ b/bookwyrm/templates/edit_book.html @@ -17,49 +17,51 @@

Added: {{ book.created_date | naturaltime }}

Updated: {{ book.updated_date | naturaltime }}

+

Last edited by: {{ book.last_edited_by.display_name }}

-{% if login_form.non_field_errors %} +{% if form.non_field_errors %}
-

{{ login_form.non_field_errors }}

+

{{ form.non_field_errors }}

{% endif %}
{% csrf_token %} +

Metadata

-

{{ form.title }}

+

{{ form.title }}

{% for error in form.title.errors %}

{{ error | escape }}

{% endfor %} -

{{ form.sort_title }}

+

{{ form.sort_title }}

{% for error in form.sort_title.errors %}

{{ error | escape }}

{% endfor %} -

{{ form.subtitle }}

+

{{ form.subtitle }}

{% for error in form.subtitle.errors %}

{{ error | escape }}

{% endfor %} -

{{ form.description }}

+

{{ form.description }}

{% for error in form.description.errors %}

{{ error | escape }}

{% endfor %} -

{{ form.series }}

+

{{ form.series }}

{% for error in form.series.errors %}

{{ error | escape }}

{% endfor %} -

{{ form.series_number }}

+

{{ form.series_number }}

{% for error in form.series_number.errors %}

{{ error | escape }}

{% endfor %} -

{{ form.first_published_date }}

+

{{ form.first_published_date }}

{% for error in form.first_published_date.errors %}

{{ error | escape }}

{% endfor %} -

{{ form.published_date }}

+

{{ form.published_date }}

{% for error in form.published_date.errors %}

{{ error | escape }}

{% endfor %} @@ -83,7 +85,7 @@

Physical Properties

-

{{ form.physical_format }}

+

{{ form.physical_format }}

{% for error in form.physical_format.errors %}

{{ error | escape }}

{% endfor %} @@ -91,7 +93,7 @@

{{ error | escape }}

{% endfor %} -

{{ form.pages }}

+

{{ form.pages }}

{% for error in form.pages.errors %}

{{ error | escape }}

{% endfor %} @@ -99,23 +101,23 @@

Book Identifiers

-

{{ form.isbn_13 }}

+

{{ form.isbn_13 }}

{% for error in form.isbn_13.errors %}

{{ error | escape }}

{% endfor %} -

{{ form.isbn_10 }}

+

{{ form.isbn_10 }}

{% for error in form.isbn_10.errors %}

{{ error | escape }}

{% endfor %} -

{{ form.openlibrary_key }}

+

{{ form.openlibrary_key }}

{% for error in form.openlibrary_key.errors %}

{{ error | escape }}

{% endfor %} -

{{ form.librarything_key }}

+

{{ form.librarything_key }}

{% for error in form.librarything_key.errors %}

{{ error | escape }}

{% endfor %} -

{{ form.goodreads_key }}

+

{{ form.goodreads_key }}

{% for error in form.goodreads_key.errors %}

{{ error | escape }}

{% endfor %} diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index e6c3f79f..22edd38a 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -76,6 +76,7 @@ urlpatterns = [ # books re_path(r'%s(.json)?/?$' % book_path, views.book_page), re_path(r'%s/edit/?$' % book_path, views.edit_book_page), + re_path(r'^author/(?P[\w\-]+)/edit/?$', views.edit_author_page), re_path(r'%s/editions(.json)?/?$' % book_path, views.editions_page), re_path(r'^author/(?P[\w\-]+)(.json)?/?$', views.author_page), @@ -104,6 +105,7 @@ urlpatterns = [ re_path(r'^edit-book/(?P\d+)/?$', actions.edit_book), re_path(r'^upload-cover/(?P\d+)/?$', actions.upload_cover), re_path(r'^add-description/(?P\d+)/?$', actions.add_description), + re_path(r'^edit-author/(?P\d+)/?$', actions.edit_author), re_path(r'^switch-edition/?$', actions.switch_edition), re_path(r'^edit-readthrough/?$', actions.edit_readthrough), diff --git a/bookwyrm/view_actions.py b/bookwyrm/view_actions.py index 7939cab1..9f834eb1 100644 --- a/bookwyrm/view_actions.py +++ b/bookwyrm/view_actions.py @@ -244,7 +244,7 @@ def edit_book(request, book_id): return TemplateResponse(request, 'edit_book.html', data) book = form.save() - outgoing.handle_update_book(request.user, book) + outgoing.handle_update_book_data(request.user, book) return redirect('/book/%s' % book.id) @@ -291,7 +291,7 @@ def upload_cover(request, book_id): book.cover = form.files['cover'] book.save() - outgoing.handle_update_book(request.user, book) + outgoing.handle_update_book_data(request.user, book) return redirect('/book/%s' % book.id) @@ -310,10 +310,31 @@ def add_description(request, book_id): book.description = description book.save() - outgoing.handle_update_book(request.user, book) + outgoing.handle_update_book_data(request.user, book) return redirect('/book/%s' % book.id) +@login_required +@permission_required('bookwyrm.edit_book', raise_exception=True) +@require_POST +def edit_author(request, author_id): + ''' edit a author cool ''' + author = get_object_or_404(models.Author, id=author_id) + + form = forms.AuthorForm(request.POST, request.FILES, instance=author) + if not form.is_valid(): + data = { + 'title': 'Edit Author', + 'author': author, + 'form': form + } + return TemplateResponse(request, 'edit_author.html', data) + author = form.save() + + outgoing.handle_update_book_data(request.user, author) + return redirect('/author/%s' % author.id) + + @login_required @require_POST def create_shelf(request): diff --git a/bookwyrm/views.py b/bookwyrm/views.py index 8e40f362..1afb8266 100644 --- a/bookwyrm/views.py +++ b/bookwyrm/views.py @@ -657,6 +657,20 @@ def edit_book_page(request, book_id): return TemplateResponse(request, 'edit_book.html', data) +@login_required +@permission_required('bookwyrm.edit_book', raise_exception=True) +@require_GET +def edit_author_page(request, author_id): + ''' info about a book ''' + author = get_object_or_404(models.Author, id=author_id) + data = { + 'title': 'Edit Author', + 'author': author, + 'form': forms.AuthorForm(instance=author) + } + return TemplateResponse(request, 'edit_author.html', data) + + @require_GET def editions_page(request, book_id): ''' list of editions of a book '''