Adds delete list view

This commit is contained in:
Mouse Reeve 2021-09-06 10:38:37 -07:00
parent 1e037d20a4
commit c630ec3572
3 changed files with 17 additions and 0 deletions

View file

@ -220,6 +220,7 @@ urlpatterns = [
re_path(r"^list/?$", views.Lists.as_view(), name="lists"),
re_path(r"^list/saved/?$", views.SavedLists.as_view(), name="saved-lists"),
re_path(r"^list/(?P<list_id>\d+)(.json)?/?$", views.List.as_view(), name="list"),
re_path(r"^list/delete/(?P<list_id>\d+)/?$", views.delete_list, name="delete-list"),
re_path(r"^list/add-book/?$", views.list.add_book, name="list-add-book"),
re_path(
r"^list/(?P<list_id>\d+)/remove/?$",

View file

@ -27,6 +27,7 @@ from .isbn import Isbn
from .landing import About, Home, Landing
from .list import Lists, SavedLists, List, Curate, UserLists
from .list import save_list, unsave_list
from .list import delete_list
from .notifications import Notifications
from .outbox import Outbox
from .reading import edit_readthrough, create_readthrough

View file

@ -3,6 +3,7 @@ from typing import Optional
from urllib.parse import urlencode
from django.contrib.auth.decorators import login_required
from django.core.exceptions import PermissionDenied
from django.core.paginator import Paginator
from django.db import IntegrityError, transaction
from django.db.models import Avg, Count, DecimalField, Q, Max
@ -260,6 +261,20 @@ def unsave_list(request, list_id):
return redirect("list", list_id)
@require_POST
@login_required
def delete_list(request, list_id):
"""delete a list"""
book_list = get_object_or_404(models.List, id=list_id)
# only the owner or a moderator can delete a list
if book_list.user != request.user and not request.user.has_perm("moderate_post"):
raise PermissionDenied
book_list.delete()
return redirect("lists")
@require_POST
@login_required
def add_book(request):