forked from mirrors/bookwyrm
Adds openlibrary update for book
This commit is contained in:
parent
113eda33e9
commit
d7e4e6aa1e
7 changed files with 25 additions and 7 deletions
|
@ -196,12 +196,12 @@ class AbstractConnector(AbstractMinimalConnector):
|
||||||
|
|
||||||
def update_author_from_remote(self, obj):
|
def update_author_from_remote(self, obj):
|
||||||
"""load the remote data from this connector and add it to an existing author"""
|
"""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)
|
return self.get_or_create_author(remote_id, instance=obj)
|
||||||
|
|
||||||
def update_book_from_remote(self, obj):
|
def update_book_from_remote(self, obj):
|
||||||
"""load the remote data from this connector and add it to an existing book"""
|
"""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)
|
data = self.get_book_data(remote_id)
|
||||||
return self.create_edition_from_data(obj.parent_work, data, instance=obj)
|
return self.create_edition_from_data(obj.parent_work, data, instance=obj)
|
||||||
|
|
||||||
|
|
|
@ -77,6 +77,9 @@
|
||||||
<a itemprop="sameAs" href="{{ author.openlibrary_link }}" target="_blank" rel="noopener">
|
<a itemprop="sameAs" href="{{ author.openlibrary_link }}" target="_blank" rel="noopener">
|
||||||
{% trans "View on OpenLibrary" %}
|
{% trans "View on OpenLibrary" %}
|
||||||
</a>
|
</a>
|
||||||
|
{% if request.user.is_authenticated and perms.bookwyrm.edit_book %}
|
||||||
|
<button class="button is-small" type="button">{% trans "Update from OpenLibrary" %}</button>
|
||||||
|
{% endif %}
|
||||||
</p>
|
</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
@ -85,6 +88,9 @@
|
||||||
<a itemprop="sameAs" href="{{ author.inventaire_link }}" target="_blank" rel="noopener">
|
<a itemprop="sameAs" href="{{ author.inventaire_link }}" target="_blank" rel="noopener">
|
||||||
{% trans "View on Inventaire" %}
|
{% trans "View on Inventaire" %}
|
||||||
</a>
|
</a>
|
||||||
|
{% if request.user.is_authenticated and perms.bookwyrm.edit_book %}
|
||||||
|
<button class="button is-small" type="button">{% trans "Update from Inventaire" %}</button>
|
||||||
|
{% endif %}
|
||||||
</p>
|
</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
|
@ -91,7 +91,13 @@
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
|
|
||||||
{% if book.openlibrary_key %}
|
{% if book.openlibrary_key %}
|
||||||
<p><a href="{{ book.openlibrary_link }}" target="_blank" rel="noopener">{% trans "View on OpenLibrary" %}</a></p>
|
<p>
|
||||||
|
<a href="{{ book.openlibrary_link }}" target="_blank" rel="noopener">{% trans "View on OpenLibrary" %}</a>
|
||||||
|
<form name="ol-update" method="POST" action="{% url 'book-update-remote' book.id 'openlibrary.org' %}">
|
||||||
|
{% csrf_token %}
|
||||||
|
<button class="button is-small" type="submit">{% trans "Update from OpenLibrary" %}</button>
|
||||||
|
</form>
|
||||||
|
</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if book.inventaire_id %}
|
{% if book.inventaire_id %}
|
||||||
<p><a href="{{ book.inventaire_link }}" target="_blank" rel="noopener">{% trans "View on Inventaire" %}</a></p>
|
<p><a href="{{ book.inventaire_link }}" target="_blank" rel="noopener">{% trans "View on Inventaire" %}</a></p>
|
||||||
|
|
|
@ -422,8 +422,13 @@ urlpatterns = [
|
||||||
r"^upload-cover/(?P<book_id>\d+)/?$", views.upload_cover, name="upload-cover"
|
r"^upload-cover/(?P<book_id>\d+)/?$", views.upload_cover, name="upload-cover"
|
||||||
),
|
),
|
||||||
re_path(r"^add-description/(?P<book_id>\d+)/?$", views.add_description),
|
re_path(r"^add-description/(?P<book_id>\d+)/?$", views.add_description),
|
||||||
re_path(r"^resolve-book/?$", views.resolve_book),
|
re_path(r"^resolve-book/?$", views.resolve_book, name="resolve-book"),
|
||||||
re_path(r"^switch-edition/?$", views.switch_edition),
|
re_path(r"^switch-edition/?$", views.switch_edition, name="switch-edition"),
|
||||||
|
re_path(
|
||||||
|
rf"{BOOK_PATH}/update/(?P<connector_identifier>[\w\.]+)?$",
|
||||||
|
views.update_book_from_remote,
|
||||||
|
name="book-update-remote"
|
||||||
|
),
|
||||||
# isbn
|
# isbn
|
||||||
re_path(r"^isbn/(?P<isbn>\d+)(.json)?/?$", views.Isbn.as_view()),
|
re_path(r"^isbn/(?P<isbn>\d+)(.json)?/?$", views.Isbn.as_view()),
|
||||||
# author
|
# author
|
||||||
|
|
|
@ -29,6 +29,7 @@ from .preferences.block import Block, unblock
|
||||||
|
|
||||||
# books
|
# books
|
||||||
from .books.books import Book, upload_cover, add_description, resolve_book
|
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.edit_book import EditBook, ConfirmEditBook
|
||||||
from .books.editions import Editions, switch_edition
|
from .books.editions import Editions, switch_edition
|
||||||
|
|
||||||
|
|
|
@ -81,7 +81,7 @@ class EditAuthor(View):
|
||||||
@require_POST
|
@require_POST
|
||||||
@permission_required("bookwyrm.edit_book", raise_exception=True)
|
@permission_required("bookwyrm.edit_book", raise_exception=True)
|
||||||
# pylint: disable=unused-argument
|
# 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"""
|
"""load the remote data for this author"""
|
||||||
connector = connector_manager.load_connector(
|
connector = connector_manager.load_connector(
|
||||||
get_object_or_404(models.Connector, identifier=connector_identifier)
|
get_object_or_404(models.Connector, identifier=connector_identifier)
|
||||||
|
|
|
@ -184,7 +184,7 @@ def resolve_book(request):
|
||||||
@require_POST
|
@require_POST
|
||||||
@permission_required("bookwyrm.edit_book", raise_exception=True)
|
@permission_required("bookwyrm.edit_book", raise_exception=True)
|
||||||
# pylint: disable=unused-argument
|
# 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"""
|
"""load the remote data for this book"""
|
||||||
connector = connector_manager.load_connector(
|
connector = connector_manager.load_connector(
|
||||||
get_object_or_404(models.Connector, identifier=connector_identifier)
|
get_object_or_404(models.Connector, identifier=connector_identifier)
|
||||||
|
|
Loading…
Reference in a new issue