Fix signature for UserUpdateView.get_object

This commit is contained in:
Bruno Alla 2024-07-28 09:59:08 +02:00
parent dd15c83977
commit a8105bdc9f
No known key found for this signature in database

View File

@ -1,5 +1,6 @@
from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.messages.views import SuccessMessageMixin
from django.db.models import QuerySet
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
from django.views.generic import DetailView
@ -28,12 +29,12 @@ class UserUpdateView(LoginRequiredMixin, SuccessMessageMixin, UpdateView):
fields = ["name"]
success_message = _("Information successfully updated")
def get_success_url(self):
def get_success_url(self) -> str:
# for mypy to know that the user is authenticated
assert self.request.user.is_authenticated
return self.request.user.get_absolute_url()
def get_object(self):
def get_object(self, queryset: QuerySet | None=None) -> User:
return self.request.user
@ -43,7 +44,7 @@ user_update_view = UserUpdateView.as_view()
class UserRedirectView(LoginRequiredMixin, RedirectView):
permanent = False
def get_redirect_url(self):
def get_redirect_url(self) -> str:
{%- if cookiecutter.username_type == "email" %}
return reverse("users:detail", kwargs={"pk": self.request.user.pk})
{%- else %}