diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/views.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/views.py index 011ea410..803769fa 100644 --- a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/views.py +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/views.py @@ -1,6 +1,6 @@ -from django.contrib import messages 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 @@ -18,23 +18,18 @@ class UserDetailView(LoginRequiredMixin, DetailView): user_detail_view = UserDetailView.as_view() -class UserUpdateView(LoginRequiredMixin, UpdateView): +class UserUpdateView(LoginRequiredMixin, SuccessMessageMixin, UpdateView): model = User fields = ["name"] + success_message = _("Information successfully updated") def get_success_url(self): return reverse("users:detail", kwargs={"username": self.request.user.username}) def get_object(self): return self.request.user - - def form_valid(self, form): - messages.add_message( - self.request, messages.INFO, _("Information successfully updated") - ) - return super().form_valid(form) - + user_update_view = UserUpdateView.as_view() @@ -47,4 +42,4 @@ class UserRedirectView(LoginRequiredMixin, RedirectView): return reverse("users:detail", kwargs={"username": self.request.user.username}) -user_redirect_view = UserRedirectView.as_view() +user_redirect_view = UserRedirectView.as_view() \ No newline at end of file