Adds type annotation to suggestion list view file

This commit is contained in:
Mouse Reeve 2024-08-27 18:22:50 -07:00
parent 6b622bac3e
commit 0b171b0ba9
2 changed files with 19 additions and 7 deletions

View file

@ -1,8 +1,11 @@
""" the good stuff! the books! """ """ the good stuff! the books! """
from typing import Any
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.core.paginator import Paginator from django.core.paginator import Paginator
from django.db import transaction from django.db import transaction
from django.db.models import Count, Q from django.db.models import Count, Q
from django.http import HttpRequest, HttpResponse
from django.shortcuts import get_object_or_404 from django.shortcuts import get_object_or_404
from django.template.response import TemplateResponse from django.template.response import TemplateResponse
from django.urls import reverse from django.urls import reverse
@ -21,7 +24,9 @@ from bookwyrm.views.list.list import get_list_suggestions
class SuggestionList(View): class SuggestionList(View):
"""book list page""" """book list page"""
def get(self, request, book_id, **kwargs): def get(
self, request: HttpRequest, book_id: int, **kwargs: Any
) -> ActivitypubResponse | TemplateResponse:
"""display a book list""" """display a book list"""
add_failed = kwargs.get("add_failed", False) add_failed = kwargs.get("add_failed", False)
add_succeeded = kwargs.get("add_succeeded", False) add_succeeded = kwargs.get("add_succeeded", False)
@ -29,7 +34,6 @@ class SuggestionList(View):
work = models.Work.objects.filter( work = models.Work.objects.filter(
Q(id=book_id) | Q(editions=book_id) Q(id=book_id) | Q(editions=book_id)
).distinct() ).distinct()
print(work.count())
work = work.first() work = work.first()
book_list = get_object_or_404(models.SuggestionList, suggests_for=work) book_list = get_object_or_404(models.SuggestionList, suggests_for=work)
@ -49,7 +53,7 @@ class SuggestionList(View):
page = paginated.get_page(request.GET.get("page")) page = paginated.get_page(request.GET.get("page"))
embed_key = str(book_list.embed_key.hex) embed_key = str(book_list.embed_key.hex) # type: ignore
embed_url = reverse("embed-list", args=[book_list.id, embed_key]) embed_url = reverse("embed-list", args=[book_list.id, embed_key])
embed_url = request.build_absolute_uri(embed_url) embed_url = request.build_absolute_uri(embed_url)
@ -79,7 +83,9 @@ class SuggestionList(View):
return TemplateResponse(request, "lists/list.html", data) return TemplateResponse(request, "lists/list.html", data)
@method_decorator(login_required, name="dispatch") @method_decorator(login_required, name="dispatch")
def post(self, request, book_id): # pylint: disable=unused-argument def post(
self, request: HttpRequest, book_id: int
) -> Any: # pylint: disable=unused-argument
"""create a suggestion_list""" """create a suggestion_list"""
form = forms.SuggestionListForm(request.POST) form = forms.SuggestionListForm(request.POST)
@ -95,7 +101,7 @@ class SuggestionList(View):
@login_required @login_required
@require_POST @require_POST
def book_add_suggestion(request, book_id): def book_add_suggestion(request: HttpRequest, book_id: int) -> Any:
"""put a book on the suggestion list""" """put a book on the suggestion list"""
_ = get_object_or_404( _ = get_object_or_404(
models.SuggestionList, suggests_for=book_id, id=request.POST.get("book_list") models.SuggestionList, suggests_for=book_id, id=request.POST.get("book_list")
@ -112,7 +118,7 @@ def book_add_suggestion(request, book_id):
@require_POST @require_POST
@login_required @login_required
def book_remove_suggestion(request, book_id): def book_remove_suggestion(request: HttpRequest, book_id: int) -> Any:
"""remove a book from a suggestion list""" """remove a book from a suggestion list"""
item = get_object_or_404( item = get_object_or_404(
models.SuggestionListItem, models.SuggestionListItem,
@ -129,7 +135,7 @@ def book_remove_suggestion(request, book_id):
@require_POST @require_POST
@login_required @login_required
def endorse_suggestion(request, book_id, item_id): def endorse_suggestion(request: HttpRequest, book_id: int, item_id: int) -> Any:
"""endorse a suggestion""" """endorse a suggestion"""
item = get_object_or_404( item = get_object_or_404(
models.SuggestionListItem, id=item_id, book_list__suggests_for=book_id models.SuggestionListItem, id=item_id, book_list__suggests_for=book_id

View file

@ -22,6 +22,12 @@ ignore_errors = False
[mypy-bookwyrm.isbn.*] [mypy-bookwyrm.isbn.*]
ignore_errors = False ignore_errors = False
[mypy-bookwyrm.views.suggestion_list]
ignore_errors = False
allow_untyped_calls = True
disable_error_code = assignment
[mypy-celerywyrm.*] [mypy-celerywyrm.*]
ignore_errors = False ignore_errors = False