Skip to content

Commit

Permalink
Admin action to mass deactivate social workers
Browse files Browse the repository at this point in the history
  • Loading branch information
christophehenry committed Dec 23, 2021
1 parent 71fde98 commit 54f0795
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions aidants_connect_web/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 54f0795

Please sign in to comment.