Merge pull request #2012 from bookwyrm-social/catch-update-book-error
Catch update book error
This commit is contained in:
commit
753cd36f86
|
@ -12,6 +12,15 @@
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
{% if update_error %}
|
||||||
|
<div class="notification is-danger is-light">
|
||||||
|
<span class="icon icon-x" aria-hidden="true"></span>
|
||||||
|
<span>
|
||||||
|
{% trans "Unable to connect to remote source." %}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% with user_authenticated=request.user.is_authenticated can_edit_book=perms.bookwyrm.edit_book %}
|
{% with user_authenticated=request.user.is_authenticated can_edit_book=perms.bookwyrm.edit_book %}
|
||||||
<div class="block" itemscope itemtype="https://schema.org/Book">
|
<div class="block" itemscope itemtype="https://schema.org/Book">
|
||||||
<div class="columns is-mobile">
|
<div class="columns is-mobile">
|
||||||
|
|
|
@ -12,7 +12,7 @@ from django.views.decorators.http import require_POST
|
||||||
|
|
||||||
from bookwyrm import forms, models
|
from bookwyrm import forms, models
|
||||||
from bookwyrm.activitypub import ActivitypubResponse
|
from bookwyrm.activitypub import ActivitypubResponse
|
||||||
from bookwyrm.connectors import connector_manager
|
from bookwyrm.connectors import connector_manager, ConnectorException
|
||||||
from bookwyrm.connectors.abstract_connector import get_image
|
from bookwyrm.connectors.abstract_connector import get_image
|
||||||
from bookwyrm.settings import PAGE_LENGTH
|
from bookwyrm.settings import PAGE_LENGTH
|
||||||
from bookwyrm.views.helpers import is_api_request
|
from bookwyrm.views.helpers import is_api_request
|
||||||
|
@ -22,7 +22,7 @@ from bookwyrm.views.helpers import is_api_request
|
||||||
class Book(View):
|
class Book(View):
|
||||||
"""a book! this is the stuff"""
|
"""a book! this is the stuff"""
|
||||||
|
|
||||||
def get(self, request, book_id, user_statuses=False):
|
def get(self, request, book_id, user_statuses=False, update_error=False):
|
||||||
"""info about a book"""
|
"""info about a book"""
|
||||||
if is_api_request(request):
|
if is_api_request(request):
|
||||||
book = get_object_or_404(
|
book = get_object_or_404(
|
||||||
|
@ -80,6 +80,7 @@ class Book(View):
|
||||||
else None,
|
else None,
|
||||||
"rating": reviews.aggregate(Avg("rating"))["rating__avg"],
|
"rating": reviews.aggregate(Avg("rating"))["rating__avg"],
|
||||||
"lists": lists,
|
"lists": lists,
|
||||||
|
"update_error": update_error,
|
||||||
}
|
}
|
||||||
|
|
||||||
if request.user.is_authenticated:
|
if request.user.is_authenticated:
|
||||||
|
@ -191,6 +192,10 @@ def update_book_from_remote(request, book_id, connector_identifier):
|
||||||
)
|
)
|
||||||
book = get_object_or_404(models.Book.objects.select_subclasses(), id=book_id)
|
book = get_object_or_404(models.Book.objects.select_subclasses(), id=book_id)
|
||||||
|
|
||||||
connector.update_book_from_remote(book)
|
try:
|
||||||
|
connector.update_book_from_remote(book)
|
||||||
|
except ConnectorException:
|
||||||
|
# the remote source isn't available or doesn't know this book
|
||||||
|
return Book().get(request, book_id, update_error=True)
|
||||||
|
|
||||||
return redirect("book", book.id)
|
return redirect("book", book.id)
|
||||||
|
|
Loading…
Reference in New Issue