From 1af50c0f4c54844d8c115238581e26ed95328cbb Mon Sep 17 00:00:00 2001 From: virusdefender Date: Mon, 11 Mar 2019 11:43:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E7=94=A8=E6=88=B7=E7=9A=84?= =?UTF-8?q?=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- account/views/admin.py | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/account/views/admin.py b/account/views/admin.py index 04e21e03..581a607e 100644 --- a/account/views/admin.py +++ b/account/views/admin.py @@ -121,25 +121,15 @@ class UserAdminAPI(APIView): Q(email__icontains=keyword)) return self.success(self.paginate_data(request, user, UserAdminSerializer)) - def delete_one(self, user_id): - try: - user = User.objects.get(id=user_id) - except User.DoesNotExist: - return f"User {user_id} does not exist" - if Submission.objects.filter(user_id=user_id).exists(): - return f"Can't delete the user {user_id} as he/she has submissions" - user.delete() - @super_admin_required def delete(self, request): id = request.GET.get("id") if not id: return self.error("Invalid Parameter, id is required") - for user_id in id.split(","): - if user_id: - error = self.delete_one(user_id) - if error: - return self.error(error) + ids = id.split(",") + if str(request.user.id) in ids: + return self.error("Current user can not be deleted") + User.objects.filter(id__in=ids).delete() return self.success()