From 6f4cff535a3d8b10c9a2bc227502768d76103997 Mon Sep 17 00:00:00 2001 From: Christophe Henry Date: Thu, 23 Dec 2021 15:03:06 +0100 Subject: [PATCH] Admin action to mass deactivate social workers --- aidants_connect_web/admin.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/aidants_connect_web/admin.py b/aidants_connect_web/admin.py index 50d6485a1..6860083f1 100644 --- a/aidants_connect_web/admin.py +++ b/aidants_connect_web/admin.py @@ -8,8 +8,8 @@ from django.contrib import messages from django.contrib.admin import ModelAdmin, TabularInline, SimpleListFilter from django.contrib.auth.admin import UserAdmin as DjangoUserAdmin -from django.db.models import Q -from django.http import HttpResponseRedirect, HttpResponseNotAllowed +from django.db.models import Q, QuerySet +from django.http import HttpResponseRedirect, HttpResponseNotAllowed, HttpRequest from django.shortcuts import render from django.urls import reverse, path from django.utils.html import format_html_join @@ -479,6 +479,7 @@ def display_totp_device_status(self, obj): # The forms to add and change `Aidant` instances form = AidantChangeForm add_form = AidantCreationForm + actions = ["mass_deactivate"] raw_id_fields = ("responsable_de", "organisation", "organisations") readonly_fields = ( "validated_cgu_version", @@ -579,6 +580,12 @@ def save_related(self, request, form, formsets, change): if organisation is not None: form.instance.organisations.add(organisation) + def mass_deactivate(self, request: HttpRequest, queryset: QuerySet): + queryset.update(is_active=False) + self.message_user(request, f"{queryset.count()} profils ont été désactivés") + + mass_deactivate.short_description = "Désactiver les profils sélectionnés" + class HabilitationRequestResource(resources.ModelResource): created_at = Field(attribute="created_at", column_name="Date d'ajout")