forked from DGNum/gestioCOF
UserDelete view
This commit is contained in:
parent
85c750d380
commit
a259dd524f
2 changed files with 16 additions and 2 deletions
|
@ -13,4 +13,5 @@ urlpatterns = [
|
||||||
views.UserCreateView.as_view(),
|
views.UserCreateView.as_view(),
|
||||||
name="user.create.fromclipper",
|
name="user.create.fromclipper",
|
||||||
),
|
),
|
||||||
|
path("user/delete/<int:pk>", views.UserDeleteView.as_view(), name="user.delete"),
|
||||||
]
|
]
|
||||||
|
|
17
bds/views.py
17
bds/views.py
|
@ -1,9 +1,9 @@
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
from django.urls import reverse
|
from django.urls import reverse, reverse_lazy
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.views.generic import TemplateView
|
from django.views.generic import DeleteView, TemplateView
|
||||||
|
|
||||||
from bds.autocomplete import bds_search
|
from bds.autocomplete import bds_search
|
||||||
from bds.forms import ProfileForm, UserForm, UserFromClipperForm, UserFromScratchForm
|
from bds.forms import ProfileForm, UserForm, UserFromClipperForm, UserFromScratchForm
|
||||||
|
@ -109,3 +109,16 @@ class UserCreateView(StaffRequiredMixin, MultipleFormView):
|
||||||
def form_invalid(self, forms):
|
def form_invalid(self, forms):
|
||||||
messages.error(self.request, _("Veuillez corriger les erreurs ci-dessous"))
|
messages.error(self.request, _("Veuillez corriger les erreurs ci-dessous"))
|
||||||
return super().form_invalid(forms)
|
return super().form_invalid(forms)
|
||||||
|
|
||||||
|
|
||||||
|
class UserDeleteView(StaffRequiredMixin, DeleteView):
|
||||||
|
model = User
|
||||||
|
success_url = reverse_lazy("bds:home")
|
||||||
|
success_message = "Profil supprimé avec succès !"
|
||||||
|
|
||||||
|
def delete(self, request, *args, **kwargs):
|
||||||
|
# SuccessMessageMixin does not work with DeleteView, see :
|
||||||
|
# https://code.djangoproject.com/ticket/21926
|
||||||
|
messages.success(request, self.success_message)
|
||||||
|
|
||||||
|
return super().delete(request, *args, **kwargs)
|
||||||
|
|
Loading…
Reference in a new issue