From 92de48afd4eef0f2801f24182a1794d7456b9917 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 27 Sep 2021 10:06:46 -0700 Subject: [PATCH 1/3] Adds init file to admin views dir Is this why they're not pylinting? --- bookwyrm/views/admin/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 bookwyrm/views/admin/__init__.py diff --git a/bookwyrm/views/admin/__init__.py b/bookwyrm/views/admin/__init__.py new file mode 100644 index 000000000..e69de29bb From 28d40e99140d1c2621e03db00d604bc8a0f70321 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 27 Sep 2021 10:17:16 -0700 Subject: [PATCH 2/3] Use url names in redirects --- bookwyrm/urls.py | 2 +- bookwyrm/views/admin/invite.py | 4 +++- bookwyrm/views/block.py | 4 ++-- bookwyrm/views/edit_user.py | 4 ++-- bookwyrm/views/notifications.py | 2 +- bookwyrm/views/password.py | 4 ++-- 6 files changed, 11 insertions(+), 9 deletions(-) diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index d54347f0f..f55051812 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -56,7 +56,7 @@ urlpatterns = [ views.ConfirmEmailCode.as_view(), name="confirm-email-code", ), - re_path(r"resend-link", views.resend_link, name="resend-link"), + re_path(r"^resend-link/?$", views.resend_link, name="resend-link"), re_path(r"^logout/?$", views.Logout.as_view(), name="logout"), re_path( r"^password-reset/?$", diff --git a/bookwyrm/views/admin/invite.py b/bookwyrm/views/admin/invite.py index 44644e195..f4c82e485 100644 --- a/bookwyrm/views/admin/invite.py +++ b/bookwyrm/views/admin/invite.py @@ -51,7 +51,7 @@ class ManageInvites(View): """creates an invite database entry""" form = forms.CreateInviteForm(request.POST) if not form.is_valid(): - return HttpResponseBadRequest("ERRORS : %s" % (form.errors,)) + return HttpResponseBadRequest(f"ERRORS: {form.errors}") invite = form.save(commit=False) invite.user = request.user @@ -98,6 +98,7 @@ class ManageInviteRequests(View): "invite__times_used", "invite__invitees__created_date", ] + # pylint: disable=consider-using-f-string if not sort in sort_fields + ["-{:s}".format(f) for f in sort_fields]: sort = "-created_date" @@ -149,6 +150,7 @@ class ManageInviteRequests(View): ) invite_request.save() emailing.invite_email(invite_request) + # pylint: disable=consider-using-f-string return redirect( "{:s}?{:s}".format( reverse("settings-invite-requests"), urlencode(request.GET.dict()) diff --git a/bookwyrm/views/block.py b/bookwyrm/views/block.py index 99014a937..0b80c327d 100644 --- a/bookwyrm/views/block.py +++ b/bookwyrm/views/block.py @@ -24,7 +24,7 @@ class Block(View): models.UserBlocks.objects.create( user_subject=request.user, user_object=to_block ) - return redirect("/preferences/block") + return redirect("prefs-block") @require_POST @@ -40,4 +40,4 @@ def unblock(request, user_id): except models.UserBlocks.DoesNotExist: return HttpResponseNotFound() block.delete() - return redirect("/preferences/block") + return redirect("prefs-block") diff --git a/bookwyrm/views/edit_user.py b/bookwyrm/views/edit_user.py index 4026a5319..0a2d93275 100644 --- a/bookwyrm/views/edit_user.py +++ b/bookwyrm/views/edit_user.py @@ -34,9 +34,9 @@ class EditUser(View): data = {"form": form, "user": request.user} return TemplateResponse(request, "preferences/edit_user.html", data) - user = save_user_form(form) + save_user_form(form) - return redirect(user.local_path) + return redirect("user-feed", request.user.localname) # pylint: disable=no-self-use diff --git a/bookwyrm/views/notifications.py b/bookwyrm/views/notifications.py index b96bc9259..d6897f390 100644 --- a/bookwyrm/views/notifications.py +++ b/bookwyrm/views/notifications.py @@ -29,4 +29,4 @@ class Notifications(View): def post(self, request): """permanently delete notification for user""" request.user.notification_set.filter(read=True).delete() - return redirect("/notifications") + return redirect("notifications") diff --git a/bookwyrm/views/password.py b/bookwyrm/views/password.py index baf1b3ff4..ce055721c 100644 --- a/bookwyrm/views/password.py +++ b/bookwyrm/views/password.py @@ -97,9 +97,9 @@ class ChangePassword(View): confirm_password = request.POST.get("confirm-password") if new_password != confirm_password: - return redirect("preferences/password") + return redirect("prefs-password") request.user.set_password(new_password) request.user.save(broadcast=False, update_fields=["password"]) login(request, request.user) - return redirect(request.user.local_path) + return redirect("user-feed", request.user.localname) From 69b010a8d3fa1d31e9f1987b529af92d26cbd816 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 27 Sep 2021 10:21:46 -0700 Subject: [PATCH 3/3] f string updates --- bookwyrm/views/admin/announcements.py | 1 + bookwyrm/views/admin/federation.py | 1 + bookwyrm/views/admin/site.py | 6 +++--- bookwyrm/views/admin/user_admin.py | 1 + 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/bookwyrm/views/admin/announcements.py b/bookwyrm/views/admin/announcements.py index 05386b7b1..e778b709a 100644 --- a/bookwyrm/views/admin/announcements.py +++ b/bookwyrm/views/admin/announcements.py @@ -31,6 +31,7 @@ class Announcements(View): "end_date", "active", ] + # pylint: disable=consider-using-f-string if sort in sort_fields + ["-{:s}".format(f) for f in sort_fields]: announcements = announcements.order_by(sort) data = { diff --git a/bookwyrm/views/admin/federation.py b/bookwyrm/views/admin/federation.py index 0368a50c9..97dfd6ff0 100644 --- a/bookwyrm/views/admin/federation.py +++ b/bookwyrm/views/admin/federation.py @@ -28,6 +28,7 @@ class Federation(View): sort = request.GET.get("sort") sort_fields = ["created_date", "application_type", "server_name"] + # pylint: disable=consider-using-f-string if not sort in sort_fields + ["-{:s}".format(f) for f in sort_fields]: sort = "-created_date" servers = servers.order_by(sort) diff --git a/bookwyrm/views/admin/site.py b/bookwyrm/views/admin/site.py index 42e8a6dd5..b66fdb9f4 100644 --- a/bookwyrm/views/admin/site.py +++ b/bookwyrm/views/admin/site.py @@ -41,9 +41,9 @@ def email_preview(request): """for development, renders and example email template""" template = request.GET.get("email") data = emailing.email_data() - data["subject_path"] = "email/{}/subject.html".format(template) - data["html_content_path"] = "email/{}/html_content.html".format(template) - data["text_content_path"] = "email/{}/text_content.html".format(template) + data["subject_path"] = f"email/{template}/subject.html" + data["html_content_path"] = f"email/{template}/html_content.html" + data["text_content_path"] = f"email/{template}/text_content.html" data["reset_link"] = "https://example.com/link" data["invite_link"] = "https://example.com/link" data["confirmation_link"] = "https://example.com/link" diff --git a/bookwyrm/views/admin/user_admin.py b/bookwyrm/views/admin/user_admin.py index 574356c23..b29214e73 100644 --- a/bookwyrm/views/admin/user_admin.py +++ b/bookwyrm/views/admin/user_admin.py @@ -47,6 +47,7 @@ class UserAdminList(View): "federated_server__server_name", "is_active", ] + # pylint: disable=consider-using-f-string if sort in sort_fields + ["-{:s}".format(f) for f in sort_fields]: users = users.order_by(sort)