From d7e4e6aa1e45a9bdd8c55eba449d06b4ff4f422f Mon Sep 17 00:00:00 2001
From: Mouse Reeve
Date: Sun, 5 Dec 2021 13:02:42 -0800
Subject: [PATCH] Adds openlibrary update for book
---
bookwyrm/connectors/abstract_connector.py | 4 ++--
bookwyrm/templates/author/author.html | 6 ++++++
bookwyrm/templates/book/book.html | 8 +++++++-
bookwyrm/urls.py | 9 +++++++--
bookwyrm/views/__init__.py | 1 +
bookwyrm/views/author.py | 2 +-
bookwyrm/views/books/books.py | 2 +-
7 files changed, 25 insertions(+), 7 deletions(-)
diff --git a/bookwyrm/connectors/abstract_connector.py b/bookwyrm/connectors/abstract_connector.py
index 97ac9249..48d2b4cb 100644
--- a/bookwyrm/connectors/abstract_connector.py
+++ b/bookwyrm/connectors/abstract_connector.py
@@ -196,12 +196,12 @@ class AbstractConnector(AbstractMinimalConnector):
def update_author_from_remote(self, obj):
"""load the remote data from this connector and add it to an existing author"""
- remote_id = obj.getattr(self, "generated_remote_link_field")
+ remote_id = getattr(obj, getattr(self, "generated_remote_link_field"))
return self.get_or_create_author(remote_id, instance=obj)
def update_book_from_remote(self, obj):
"""load the remote data from this connector and add it to an existing book"""
- remote_id = obj.getattr(self, "generated_remote_link_field")
+ remote_id = getattr(obj, getattr(self, "generated_remote_link_field"))
data = self.get_book_data(remote_id)
return self.create_edition_from_data(obj.parent_work, data, instance=obj)
diff --git a/bookwyrm/templates/author/author.html b/bookwyrm/templates/author/author.html
index fb682176..c2355955 100644
--- a/bookwyrm/templates/author/author.html
+++ b/bookwyrm/templates/author/author.html
@@ -77,6 +77,9 @@
{% trans "View on OpenLibrary" %}
+ {% if request.user.is_authenticated and perms.bookwyrm.edit_book %}
+
+ {% endif %}
{% endif %}
@@ -85,6 +88,9 @@
{% trans "View on Inventaire" %}
+ {% if request.user.is_authenticated and perms.bookwyrm.edit_book %}
+
+ {% endif %}
{% endif %}
diff --git a/bookwyrm/templates/book/book.html b/bookwyrm/templates/book/book.html
index cbca31b5..3a7b1cbc 100644
--- a/bookwyrm/templates/book/book.html
+++ b/bookwyrm/templates/book/book.html
@@ -91,7 +91,13 @@
{% endwith %}
{% if book.openlibrary_key %}
- {% trans "View on OpenLibrary" %}
+
+ {% trans "View on OpenLibrary" %}
+
+
{% endif %}
{% if book.inventaire_id %}
{% trans "View on Inventaire" %}
diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py
index 514bb7e6..697028b7 100644
--- a/bookwyrm/urls.py
+++ b/bookwyrm/urls.py
@@ -422,8 +422,13 @@ urlpatterns = [
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),
+ re_path(r"^resolve-book/?$", views.resolve_book, name="resolve-book"),
+ re_path(r"^switch-edition/?$", views.switch_edition, name="switch-edition"),
+ re_path(
+ rf"{BOOK_PATH}/update/(?P[\w\.]+)?$",
+ views.update_book_from_remote,
+ name="book-update-remote"
+ ),
# isbn
re_path(r"^isbn/(?P\d+)(.json)?/?$", views.Isbn.as_view()),
# author
diff --git a/bookwyrm/views/__init__.py b/bookwyrm/views/__init__.py
index d79de424..b399b90a 100644
--- a/bookwyrm/views/__init__.py
+++ b/bookwyrm/views/__init__.py
@@ -29,6 +29,7 @@ from .preferences.block import Block, unblock
# books
from .books.books import Book, upload_cover, add_description, resolve_book
+from .books.books import update_book_from_remote
from .books.edit_book import EditBook, ConfirmEditBook
from .books.editions import Editions, switch_edition
diff --git a/bookwyrm/views/author.py b/bookwyrm/views/author.py
index fdf86cd4..838d1c2b 100644
--- a/bookwyrm/views/author.py
+++ b/bookwyrm/views/author.py
@@ -81,7 +81,7 @@ class EditAuthor(View):
@require_POST
@permission_required("bookwyrm.edit_book", raise_exception=True)
# pylint: disable=unused-argument
-def update_author_from_remote(request, connector_identifier, author_id):
+def update_author_from_remote(request, author_id, connector_identifier):
"""load the remote data for this author"""
connector = connector_manager.load_connector(
get_object_or_404(models.Connector, identifier=connector_identifier)
diff --git a/bookwyrm/views/books/books.py b/bookwyrm/views/books/books.py
index f7166749..2d49ae30 100644
--- a/bookwyrm/views/books/books.py
+++ b/bookwyrm/views/books/books.py
@@ -184,7 +184,7 @@ def resolve_book(request):
@require_POST
@permission_required("bookwyrm.edit_book", raise_exception=True)
# pylint: disable=unused-argument
-def update_book_from_remote(request, connector_identifier, book_id):
+def update_book_from_remote(request, book_id, connector_identifier):
"""load the remote data for this book"""
connector = connector_manager.load_connector(
get_object_or_404(models.Connector, identifier=connector_identifier)