From c8c0479ce5e365f1599d2566bd1072f411f8d404 Mon Sep 17 00:00:00 2001 From: ibuler Date: Wed, 6 Jun 2018 15:18:23 +0800 Subject: [PATCH] =?UTF-8?q?[Update]=20=E4=BF=AE=E6=94=B9=E6=B8=85=E7=90=86?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=BB=84=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/clean_duplicate_user_groups.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/utils/clean_duplicate_user_groups.py b/utils/clean_duplicate_user_groups.py index be8b2d9ec..6d00af3e8 100644 --- a/utils/clean_duplicate_user_groups.py +++ b/utils/clean_duplicate_user_groups.py @@ -17,9 +17,14 @@ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "jumpserver.settings") django.setup() from users.models import UserGroup +from django.core.exceptions import FieldError def clean_group(interactive=True): + try: + UserGroup.objects.all().filter(is_discard=True).delete() + except FieldError: + pass groups = UserGroup.objects.all() groups_name_list = groups.values_list('name', flat=True) groups_with_info = groups.annotate(Count('users'))\ @@ -50,7 +55,7 @@ def clean_group(interactive=True): "Delete user group <{}>, create at {}? ([y]/n)".format( name, group.date_created) ) - if confirm.lower() == "y": + if confirm.lower() in ["y", ""]: confirm = True break elif confirm.lower() == "n":