From 6bc0d57a5290515b1f9638fbd0ca0dc6f3503a4e Mon Sep 17 00:00:00 2001 From: Stephan Telling Date: Fri, 14 Apr 2017 16:11:43 +0200 Subject: [PATCH] add admin actions to add/remove users from teams --- src/teams/admin.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/teams/admin.py b/src/teams/admin.py index cf306dc1..3ffe9b35 100644 --- a/src/teams/admin.py +++ b/src/teams/admin.py @@ -4,6 +4,7 @@ from .models import Team, TeamArea, TeamMember admin.site.register(TeamArea) + @admin.register(Team) class TeamAdmin(admin.ModelAdmin): def get_responsible(self, obj): @@ -22,6 +23,7 @@ class TeamAdmin(admin.ModelAdmin): 'needs_members', ] + @admin.register(TeamMember) class TeamMemberAdmin(admin.ModelAdmin): list_filter = [ @@ -29,4 +31,28 @@ class TeamMemberAdmin(admin.ModelAdmin): 'approved', ] + actions = ['add_member', 'remove_member'] + def add_member(self, request, queryset): + teams_count = queryset.values('team').distinct().count() + rows_updated = queryset.update(approved=True) + self.message_user( + request, + 'Added {} user(s) to {} team(s).'.format( + rows_updated, + teams_count + ) + ) + add_member.description = 'Add a user to the team.' + + def remove_member(self, request, queryset): + teams_count = queryset.values('team').distinct().count() + users_removed = queryset.delete()[0] + self.message_user( + request, + 'Removed {} user(s) from {} team(s).'.format( + users_removed, + teams_count + ) + ) + remove_member.description = 'Remove a user from the team.'