Merge pull request #1461 from bookwyrm-social/views-init

Adds init file to admin views dir
This commit is contained in:
Mouse Reeve 2021-09-27 10:37:23 -07:00 committed by GitHub
commit eb34bb2d93
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 17 additions and 12 deletions

View file

@ -56,7 +56,7 @@ urlpatterns = [
views.ConfirmEmailCode.as_view(), views.ConfirmEmailCode.as_view(),
name="confirm-email-code", 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"^logout/?$", views.Logout.as_view(), name="logout"),
re_path( re_path(
r"^password-reset/?$", r"^password-reset/?$",

View file

View file

@ -31,6 +31,7 @@ class Announcements(View):
"end_date", "end_date",
"active", "active",
] ]
# pylint: disable=consider-using-f-string
if sort in sort_fields + ["-{:s}".format(f) for f in sort_fields]: if sort in sort_fields + ["-{:s}".format(f) for f in sort_fields]:
announcements = announcements.order_by(sort) announcements = announcements.order_by(sort)
data = { data = {

View file

@ -28,6 +28,7 @@ class Federation(View):
sort = request.GET.get("sort") sort = request.GET.get("sort")
sort_fields = ["created_date", "application_type", "server_name"] 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]: if not sort in sort_fields + ["-{:s}".format(f) for f in sort_fields]:
sort = "-created_date" sort = "-created_date"
servers = servers.order_by(sort) servers = servers.order_by(sort)

View file

@ -51,7 +51,7 @@ class ManageInvites(View):
"""creates an invite database entry""" """creates an invite database entry"""
form = forms.CreateInviteForm(request.POST) form = forms.CreateInviteForm(request.POST)
if not form.is_valid(): if not form.is_valid():
return HttpResponseBadRequest("ERRORS : %s" % (form.errors,)) return HttpResponseBadRequest(f"ERRORS: {form.errors}")
invite = form.save(commit=False) invite = form.save(commit=False)
invite.user = request.user invite.user = request.user
@ -98,6 +98,7 @@ class ManageInviteRequests(View):
"invite__times_used", "invite__times_used",
"invite__invitees__created_date", "invite__invitees__created_date",
] ]
# pylint: disable=consider-using-f-string
if not sort in sort_fields + ["-{:s}".format(f) for f in sort_fields]: if not sort in sort_fields + ["-{:s}".format(f) for f in sort_fields]:
sort = "-created_date" sort = "-created_date"
@ -149,6 +150,7 @@ class ManageInviteRequests(View):
) )
invite_request.save() invite_request.save()
emailing.invite_email(invite_request) emailing.invite_email(invite_request)
# pylint: disable=consider-using-f-string
return redirect( return redirect(
"{:s}?{:s}".format( "{:s}?{:s}".format(
reverse("settings-invite-requests"), urlencode(request.GET.dict()) reverse("settings-invite-requests"), urlencode(request.GET.dict())

View file

@ -41,9 +41,9 @@ def email_preview(request):
"""for development, renders and example email template""" """for development, renders and example email template"""
template = request.GET.get("email") template = request.GET.get("email")
data = emailing.email_data() data = emailing.email_data()
data["subject_path"] = "email/{}/subject.html".format(template) data["subject_path"] = f"email/{template}/subject.html"
data["html_content_path"] = "email/{}/html_content.html".format(template) data["html_content_path"] = f"email/{template}/html_content.html"
data["text_content_path"] = "email/{}/text_content.html".format(template) data["text_content_path"] = f"email/{template}/text_content.html"
data["reset_link"] = "https://example.com/link" data["reset_link"] = "https://example.com/link"
data["invite_link"] = "https://example.com/link" data["invite_link"] = "https://example.com/link"
data["confirmation_link"] = "https://example.com/link" data["confirmation_link"] = "https://example.com/link"

View file

@ -47,6 +47,7 @@ class UserAdminList(View):
"federated_server__server_name", "federated_server__server_name",
"is_active", "is_active",
] ]
# pylint: disable=consider-using-f-string
if sort in sort_fields + ["-{:s}".format(f) for f in sort_fields]: if sort in sort_fields + ["-{:s}".format(f) for f in sort_fields]:
users = users.order_by(sort) users = users.order_by(sort)

View file

@ -24,7 +24,7 @@ class Block(View):
models.UserBlocks.objects.create( models.UserBlocks.objects.create(
user_subject=request.user, user_object=to_block user_subject=request.user, user_object=to_block
) )
return redirect("/preferences/block") return redirect("prefs-block")
@require_POST @require_POST
@ -40,4 +40,4 @@ def unblock(request, user_id):
except models.UserBlocks.DoesNotExist: except models.UserBlocks.DoesNotExist:
return HttpResponseNotFound() return HttpResponseNotFound()
block.delete() block.delete()
return redirect("/preferences/block") return redirect("prefs-block")

View file

@ -34,9 +34,9 @@ class EditUser(View):
data = {"form": form, "user": request.user} data = {"form": form, "user": request.user}
return TemplateResponse(request, "preferences/edit_user.html", data) 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 # pylint: disable=no-self-use

View file

@ -29,4 +29,4 @@ class Notifications(View):
def post(self, request): def post(self, request):
"""permanently delete notification for user""" """permanently delete notification for user"""
request.user.notification_set.filter(read=True).delete() request.user.notification_set.filter(read=True).delete()
return redirect("/notifications") return redirect("notifications")

View file

@ -97,9 +97,9 @@ class ChangePassword(View):
confirm_password = request.POST.get("confirm-password") confirm_password = request.POST.get("confirm-password")
if new_password != confirm_password: if new_password != confirm_password:
return redirect("preferences/password") return redirect("prefs-password")
request.user.set_password(new_password) request.user.set_password(new_password)
request.user.save(broadcast=False, update_fields=["password"]) request.user.save(broadcast=False, update_fields=["password"])
login(request, request.user) login(request, request.user)
return redirect(request.user.local_path) return redirect("user-feed", request.user.localname)