Merge pull request #1403 from jumpserver/dev

[Update] 修改清理用户组脚本
pull/2666/head^2
老广 2018-06-06 02:25:10 -05:00 committed by GitHub
commit 283b1c1d64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 1 deletions

View File

@ -17,9 +17,14 @@ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "jumpserver.settings")
django.setup() django.setup()
from users.models import UserGroup from users.models import UserGroup
from django.core.exceptions import FieldError
def clean_group(interactive=True): def clean_group(interactive=True):
try:
UserGroup.objects.all().filter(is_discard=True).delete()
except FieldError:
pass
groups = UserGroup.objects.all() groups = UserGroup.objects.all()
groups_name_list = groups.values_list('name', flat=True) groups_name_list = groups.values_list('name', flat=True)
groups_with_info = groups.annotate(Count('users'))\ groups_with_info = groups.annotate(Count('users'))\
@ -50,7 +55,7 @@ def clean_group(interactive=True):
"Delete user group <{}>, create at {}? ([y]/n)".format( "Delete user group <{}>, create at {}? ([y]/n)".format(
name, group.date_created) name, group.date_created)
) )
if confirm.lower() == "y": if confirm.lower() in ["y", ""]:
confirm = True confirm = True
break break
elif confirm.lower() == "n": elif confirm.lower() == "n":