mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2024-11-26 03:24:01 +03:00
Using SuccessMessageMixin to pass the message to django template instead of overriding form_valid
This commit is contained in:
parent
9903cb9fcd
commit
d358fc948d
|
@ -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,10 +18,11 @@ 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})
|
||||
|
@ -29,12 +30,6 @@ class UserUpdateView(LoginRequiredMixin, UpdateView):
|
|||
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()
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user