2022-01-25 16:44:04 +00:00
|
|
|
""" 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
|
2022-02-04 20:06:47 +00:00
|
|
|
from bookwyrm.views.status import to_markdown
|
2022-01-25 16:44:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
# 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():
|
2022-02-04 20:06:47 +00:00
|
|
|
item = form.save(commit=False)
|
|
|
|
item.notes = to_markdown(item.notes)
|
|
|
|
item.save()
|
2022-02-03 18:30:30 +00:00
|
|
|
else:
|
|
|
|
raise Exception(form.errors)
|
2022-01-25 16:44:04 +00:00
|
|
|
return redirect("list", list_item.book_list.id)
|