moviewyrm/bookwyrm/views/list/list_item.py
2022-02-04 12:07:26 -08:00

27 lines
984 B
Python

""" book list views"""
from django.contrib.auth.decorators import login_required
from django.shortcuts import get_object_or_404, redirect
from django.utils.decorators import method_decorator
from django.views import View
from bookwyrm import forms, models
from bookwyrm.views.status import to_markdown
# pylint: disable=no-self-use
@method_decorator(login_required, name="dispatch")
class ListItem(View):
"""book list page"""
def post(self, request, list_id, list_item):
"""Edit a list item's notes"""
list_item = get_object_or_404(models.ListItem, id=list_item, book_list=list_id)
list_item.raise_not_editable(request.user)
form = forms.ListItemForm(request.POST, instance=list_item)
if form.is_valid():
item = form.save(commit=False)
item.notes = to_markdown(item.notes)
item.save()
else:
raise Exception(form.errors)
return redirect("list", list_item.book_list.id)