mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2025-01-27 01:34:28 +03:00
Merge pull request #3021 from arnav13081994/update_views
This commit is contained in:
commit
e62d9642d0
|
@ -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