From 22163173feb276fa54ad8678ab20c31a6b7844b7 Mon Sep 17 00:00:00 2001 From: xiaoyu <763691951@qq.com> Date: Fri, 23 Sep 2016 16:30:59 +0800 Subject: [PATCH] user bulk delete view --- apps/users/api.py | 13 ++ apps/users/models.py | 5 + apps/users/templates/users/user_list.html | 107 ++++++++++------- apps/users/templates/users/user_list.old.html | 113 ------------------ 4 files changed, 80 insertions(+), 158 deletions(-) delete mode 100644 apps/users/templates/users/user_list.old.html diff --git a/apps/users/api.py b/apps/users/api.py index c90bde910..6fb1fe7c5 100644 --- a/apps/users/api.py +++ b/apps/users/api.py @@ -98,3 +98,16 @@ class GroupDeleteApi(generics.DestroyAPIView): class UserBulkUpdateApi(ListBulkCreateUpdateDestroyAPIView): queryset = User.objects.all() serializer_class = UserBulkUpdateSerializer + + def filter_queryset(self, queryset): + id_list = self.request.query_params.get('id__in') + if id_list: + import json + try: + ids = json.loads(id_list) + except Exception as e: + logger.error(str(e)) + return queryset + if isinstance(ids, list): + queryset = queryset.filter(id__in=ids) + return queryset diff --git a/apps/users/models.py b/apps/users/models.py index 13206bdb2..200d3e038 100644 --- a/apps/users/models.py +++ b/apps/users/models.py @@ -215,6 +215,11 @@ class User(AbstractUser): user.save() user.groups.add(UserGroup.initial()) + def delete(self): + if self.is_superuser: + return + return super(User, self).delete() + @classmethod def generate_fake(cls, count=100): from random import seed, choice diff --git a/apps/users/templates/users/user_list.html b/apps/users/templates/users/user_list.html index da36ab903..0773a0871 100644 --- a/apps/users/templates/users/user_list.html +++ b/apps/users/templates/users/user_list.html @@ -11,12 +11,12 @@ - {% trans 'Name' %} - {% trans 'Username' %} + {% trans 'Name' %} + {% trans 'Username' %} {% trans 'Role' %} {% trans 'User group' %} {% trans 'Asset num' %} - {% trans 'Active' %} + {% trans 'Active' %} {% trans 'Action' %} @@ -24,45 +24,12 @@ {% endblock %} - -{% block table_body %} - {% for user in object_list %} - - - - - - - {{ user.name }} - - - {{ user.username }} - {{ user.get_role_display }} - {{ user.groups.all|join_queryset_attr:"name" }} - {{ user.name }} - - {% if user.is_expired and user.is_active %} - - {% else %} - - {% endif %} - - - {% trans 'Update' %} - - {% trans 'Delete' %} - - - {% endfor %} -{% endblock %} - {% block content_bottom_left %}
-
-
-{% endblock %} -{% block custom_foot_js %} - -{% endblock %} -