mirror of
https://github.com/leaders-of-digital-9-task/backend.git
synced 2024-11-14 13:36:40 +03:00
46 lines
1.1 KiB
Python
46 lines
1.1 KiB
Python
from django.contrib.auth import get_user_model
|
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
|
from django.contrib.messages.views import SuccessMessageMixin
|
|
from django.urls import reverse
|
|
from django.utils.translation import gettext_lazy as _
|
|
from django.views.generic import DetailView, RedirectView, UpdateView
|
|
|
|
User = get_user_model()
|
|
|
|
|
|
class UserDetailView(LoginRequiredMixin, DetailView):
|
|
|
|
model = User
|
|
slug_field = "username"
|
|
slug_url_kwarg = "username"
|
|
|
|
|
|
user_detail_view = UserDetailView.as_view()
|
|
|
|
|
|
class UserUpdateView(LoginRequiredMixin, SuccessMessageMixin, UpdateView):
|
|
|
|
model = User
|
|
fields = ["name"]
|
|
success_message = _("Information successfully updated")
|
|
|
|
def get_success_url(self):
|
|
return self.request.user.get_absolute_url()
|
|
|
|
def get_object(self):
|
|
return self.request.user
|
|
|
|
|
|
user_update_view = UserUpdateView.as_view()
|
|
|
|
|
|
class UserRedirectView(LoginRequiredMixin, RedirectView):
|
|
|
|
permanent = False
|
|
|
|
def get_redirect_url(self):
|
|
return reverse("users:detail", kwargs={"username": self.request.user.username})
|
|
|
|
|
|
user_redirect_view = UserRedirectView.as_view()
|