From 113eda33e9cf5281b8c1aa406634f76658ae0ed9 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sun, 5 Dec 2021 12:47:43 -0800 Subject: [PATCH] Adds update views --- bookwyrm/views/author.py | 18 ++++++++++++++++++ bookwyrm/views/books/books.py | 16 ++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/bookwyrm/views/author.py b/bookwyrm/views/author.py index 0c8e3e05..fdf86cd4 100644 --- a/bookwyrm/views/author.py +++ b/bookwyrm/views/author.py @@ -6,9 +6,11 @@ from django.shortcuts import get_object_or_404, redirect from django.template.response import TemplateResponse from django.utils.decorators import method_decorator from django.views import View +from django.views.decorators.http import require_POST from bookwyrm import forms, models from bookwyrm.activitypub import ActivitypubResponse +from bookwyrm.connectors import connector_manager from bookwyrm.settings import PAGE_LENGTH from bookwyrm.views.helpers import is_api_request @@ -73,3 +75,19 @@ class EditAuthor(View): author = form.save() return redirect(f"/author/{author.id}") + + +@login_required +@require_POST +@permission_required("bookwyrm.edit_book", raise_exception=True) +# pylint: disable=unused-argument +def update_author_from_remote(request, connector_identifier, author_id): + """load the remote data for this author""" + connector = connector_manager.load_connector( + get_object_or_404(models.Connector, identifier=connector_identifier) + ) + author = get_object_or_404(models.Book.objects.select_subclasses(), id=author_id) + + connector.update_author_from_remote(author) + + return redirect("author", author.id) diff --git a/bookwyrm/views/books/books.py b/bookwyrm/views/books/books.py index e495da3e..f7166749 100644 --- a/bookwyrm/views/books/books.py +++ b/bookwyrm/views/books/books.py @@ -178,3 +178,19 @@ def resolve_book(request): book = connector.get_or_create_book(remote_id) return redirect("book", book.id) + + +@login_required +@require_POST +@permission_required("bookwyrm.edit_book", raise_exception=True) +# pylint: disable=unused-argument +def update_book_from_remote(request, connector_identifier, book_id): + """load the remote data for this book""" + connector = connector_manager.load_connector( + get_object_or_404(models.Connector, identifier=connector_identifier) + ) + book = get_object_or_404(models.Book.objects.select_subclasses(), id=book_id) + + connector.update_book_from_remote(book) + + return redirect("book", book.id)