From f2d7bdbf27a911aa020799a5f5307b32c0df7ea0 Mon Sep 17 00:00:00 2001 From: Vivianne Langdon Date: Fri, 11 Mar 2022 20:14:45 -0800 Subject: [PATCH] in progress fixes for pylint --- bookwyrm/urls.py | 6 +++--- bookwyrm/views/author.py | 4 ++-- bookwyrm/views/books/books.py | 4 ++-- bookwyrm/views/feed.py | 4 ++-- bookwyrm/views/group.py | 4 ++-- bookwyrm/views/helpers.py | 5 +++-- 6 files changed, 14 insertions(+), 13 deletions(-) diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index bf12c276c..6d3409e70 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -372,7 +372,7 @@ urlpatterns = [ # groups re_path(rf"{USER_PATH}/groups/?$", views.UserGroups.as_view(), name="user-groups"), re_path( - rf"^group/(?P\d+)(.json)?/?$", views.Group.as_view(), name="group" + r"^group/(?P\d+)(.json)?/?$", views.Group.as_view(), name="group" ), re_path( rf"^group/(?P\d+){regex.SLUG}/?$", views.Group.as_view(), name="group" @@ -403,7 +403,7 @@ urlpatterns = [ re_path(rf"{USER_PATH}/lists/?$", views.UserLists.as_view(), name="user-lists"), re_path(r"^list/?$", views.Lists.as_view(), name="lists"), re_path(r"^list/saved/?$", views.SavedLists.as_view(), name="saved-lists"), - re_path(rf"^list/(?P\d+)(\.json)?/?$", views.List.as_view(), name="list"), + re_path(r"^list/(?P\d+)(\.json)?/?$", views.List.as_view(), name="list"), re_path( rf"^list/(?P\d+){regex.SLUG}/?$", views.List.as_view(), name="list" ), @@ -560,7 +560,7 @@ urlpatterns = [ re_path(r"^isbn/(?P\d+)(.json)?/?$", views.Isbn.as_view()), # author re_path( - rf"^author/(?P\d+)(.json)?/?$", views.Author.as_view(), name="author" + r"^author/(?P\d+)(.json)?/?$", views.Author.as_view(), name="author" ), re_path( rf"^author/(?P\d+){regex.SLUG}/?$", diff --git a/bookwyrm/views/author.py b/bookwyrm/views/author.py index d25b82779..fef771587 100644 --- a/bookwyrm/views/author.py +++ b/bookwyrm/views/author.py @@ -26,8 +26,8 @@ class Author(View): if is_api_request(request): return ActivitypubResponse(author.to_activity()) - if r := maybe_redirect_local_path(request, author): - return r + if redirect := maybe_redirect_local_path(request, author): + return redirect books = ( models.Work.objects.filter(Q(authors=author) | Q(editions__authors=author)) diff --git a/bookwyrm/views/books/books.py b/bookwyrm/views/books/books.py index d01062467..45550c17c 100644 --- a/bookwyrm/views/books/books.py +++ b/bookwyrm/views/books/books.py @@ -50,8 +50,8 @@ class Book(View): if not book or not book.parent_work: raise Http404() - if r := maybe_redirect_local_path(request, book): - return r + if redirect := maybe_redirect_local_path(request, book): + return redirect # all reviews for all editions of the book reviews = models.Review.privacy_filter(request.user).filter( diff --git a/bookwyrm/views/feed.py b/bookwyrm/views/feed.py index fe30b0d20..0f4931ba8 100644 --- a/bookwyrm/views/feed.py +++ b/bookwyrm/views/feed.py @@ -130,8 +130,8 @@ class Status(View): status.to_activity(pure=not is_bookwyrm_request(request)) ) - if r := maybe_redirect_local_path(request, status): - return r + if redirect := maybe_redirect_local_path(request, status): + return redirect visible_thread = ( models.Status.privacy_filter(request.user) diff --git a/bookwyrm/views/group.py b/bookwyrm/views/group.py index dca534ace..761f9635a 100644 --- a/bookwyrm/views/group.py +++ b/bookwyrm/views/group.py @@ -26,8 +26,8 @@ class Group(View): group = get_object_or_404(models.Group, id=group_id) group.raise_visible_to_user(request.user) - if r := maybe_redirect_local_path(request, group): - return r + if redirect := maybe_redirect_local_path(request, group): + return redirect lists = ( models.List.privacy_filter(request.user) diff --git a/bookwyrm/views/helpers.py b/bookwyrm/views/helpers.py index 1569108d2..a2c4b20d3 100644 --- a/bookwyrm/views/helpers.py +++ b/bookwyrm/views/helpers.py @@ -206,12 +206,13 @@ def filter_stream_by_status_type(activities, allowed_types=None): def maybe_redirect_local_path(request, model): """ - if the request had an invalid path, return a permanent redirect response to the correct one, including a slug if any. + if the request had an invalid path, return a permanent redirect response to the + correct one, including a slug if any. if path is valid, returns False. """ # don't redirect empty path for unit tests which currently have this - if request.path == "/" or request.path == model.local_path: + if request.path in ("/", model.local_path): return False new_path = model.local_path