From e01fb202ffacc87e578c77683242a44cf7f33206 Mon Sep 17 00:00:00 2001 From: nanoy Date: Sun, 23 Dec 2018 21:38:53 +0100 Subject: [PATCH] Modification dans la liste --- users/templates/users/users_index.html | 6 ++++++ users/urls.py | 1 + users/views.py | 10 ++++++++++ 3 files changed, 17 insertions(+) diff --git a/users/templates/users/users_index.html b/users/templates/users/users_index.html index 176ad57..7cc5545 100644 --- a/users/templates/users/users_index.html +++ b/users/templates/users/users_index.html @@ -17,6 +17,9 @@ Utilisateur Profil + {% if perms.auth.change_user %} + Activer / Désactiver + {% endif %} @@ -24,6 +27,9 @@ {{ user }} Profil + {% if perms.auth.change_user %} + {{ user.is_active | yesno:"Désa,A"}}ctiver + {% endif %} {% endfor %} diff --git a/users/urls.py b/users/urls.py index aa83e43..2201cae 100644 --- a/users/urls.py +++ b/users/urls.py @@ -44,4 +44,5 @@ urlpatterns = [ path('allConsumptions//', views.all_consumptions, name="allConsumptions"), path('allMenus//', views.all_menus, name="allMenus"), path('exportCSV', views.export_csv, name="exportCSV"), + path('switchActivateUser/', views.switch_activate_user, name="switchActivateUser"), ] diff --git a/users/views.py b/users/views.py index c60daa7..4f277e7 100644 --- a/users/views.py +++ b/users/views.py @@ -487,6 +487,16 @@ def all_menus(request, pk, page): menus = paginator.get_page(page) return render(request, "users/all_menus.html", {"menus": menus, "user":user}) +@active_required +@login_required +@permission_required('auth.change_user') +def switch_activate_user(request, pk): + user = get_object_or_404(User, pk=pk) + user.is_active = 1 - user.is_active + user.save() + messages.success(request, "Le statut de l'utilisateur a bien été changé") + return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/')) + ########## Groups ########## @active_required