diff --git a/bookwyrm/tests/views/test_book.py b/bookwyrm/tests/views/test_book.py index 6f6116b2e..51f8b5d56 100644 --- a/bookwyrm/tests/views/test_book.py +++ b/bookwyrm/tests/views/test_book.py @@ -299,3 +299,15 @@ class BookViews(TestCase): self.book.refresh_from_db() self.assertTrue(self.book.cover) + + def test_add_description(self): + """add a book description""" + self.local_user.groups.add(self.group) + request = self.factory.post("", {"description": "new description hi"}) + request.user = self.local_user + + views.add_description(request, self.book.id) + + self.book.refresh_from_db() + self.assertEqual(self.book.description, "new description hi") + self.assertEqual(self.book.last_edited_by, self.local_user) diff --git a/bookwyrm/views/books.py b/bookwyrm/views/books.py index 492d0cac4..d56e2f22c 100644 --- a/bookwyrm/views/books.py +++ b/bookwyrm/views/books.py @@ -339,18 +339,15 @@ def set_cover_from_url(url): @permission_required("bookwyrm.edit_book", raise_exception=True) def add_description(request, book_id): """upload a new cover""" - if not request.method == "POST": - return redirect("/") - book = get_object_or_404(models.Edition, id=book_id) description = request.POST.get("description") book.description = description book.last_edited_by = request.user - book.save() + book.save(update_fields=["description", "last_edited_by"]) - return redirect("/book/%s" % book.id) + return redirect("book", book.id) @require_POST @@ -360,7 +357,7 @@ def resolve_book(request): connector = connector_manager.get_or_create_connector(remote_id) book = connector.get_or_create_book(remote_id) - return redirect("/book/%d" % book.id) + return redirect("book", book.id) @login_required