From 81a6f4841f5fe38d1a41962951001176ba09c687 Mon Sep 17 00:00:00 2001 From: ibuler Date: Thu, 14 Jan 2016 11:01:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=94=A8=E6=88=B7=E7=BB=84?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E5=AF=BC=E8=87=B4=E8=AF=A5=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=BB=84=E9=83=BD=E4=B8=A2=E5=A4=B1=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- juser/views.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/juser/views.py b/juser/views.py index 6b9d9a56b..41baa7536 100644 --- a/juser/views.py +++ b/juser/views.py @@ -6,7 +6,7 @@ # from Crypto.PublicKey import RSA import uuid from django.contrib.auth.decorators import login_required - +from django.shortcuts import get_object_or_404 from django.db.models import Q from juser.user_api import * from jperm.perm_api import get_group_user_perm @@ -111,22 +111,18 @@ def group_edit(request): if len(UserGroup.objects.filter(name=group_name)) > 1: raise ServerError(u'%s 用户组已存在' % group_name) # add user group + user_group = get_object_or_404(UserGroup, id=group_id) + user_group.user_set.clear() + for user in User.objects.filter(id__in=users_selected): user.group.add(UserGroup.objects.get(id=group_id)) - # delete user group - user_group = UserGroup.objects.get(id=group_id) - for user in [user for user in User.objects.filter(group=user_group) if user not in User.objects.filter(id__in=users_selected)]: - user_group_all = user.group.all() - user.group.clear() - for g in user_group_all: - if g == user_group: - continue - user.group.add(g) + user_group.name = group_name user_group.comment = comment user_group.save() except ServerError, e: error = e + if not error: return HttpResponseRedirect(reverse('user_group_list')) else: