From 42ec624a91b51630559a194632b076dbaccea91a Mon Sep 17 00:00:00 2001 From: liuzheng712 Date: Fri, 20 Nov 2015 11:04:22 +0800 Subject: [PATCH 1/5] group add and remove fixed --- juser/views.py | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/juser/views.py b/juser/views.py index f0f04c79e..84f39954b 100644 --- a/juser/views.py +++ b/juser/views.py @@ -96,36 +96,37 @@ def group_edit(request): if request.method == 'GET': group_id = request.GET.get('id', '') - user_group = get_object(UserGroup, id=group_id) - if user_group: - users_all = User.objects.all() - users_selected = user_group.user_set.all() - users_remain = [user for user in users_all if user not in users_selected] + # user_group = get_object(UserGroup, id=group_id) + user_group = UserGroup.objects.get(id=group_id) + users_selected = User.objects.filter(group=user_group) + users_remain = User.objects.filter(~Q(group=user_group)) + users_all = User.objects.all() - else: + elif request.method == 'POST': group_id = request.POST.get('group_id', '') group_name = request.POST.get('group_name', '') comment = request.POST.get('comment', '') users_selected = request.POST.getlist('users_selected') - users = [] try: if '' in [group_id, group_name]: raise ServerError('组名不能为空') - user_group = get_object(UserGroup, id=group_id) - other_group = get_object(UserGroup, name=group_name) - - if other_group and other_group.id != int(group_id): + if len(UserGroup.objects.filter(name=group_name)) > 1: raise ServerError(u'%s 用户组已存在' % group_name) + # add user group + 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) - for user_id in users_selected: - users.extend(User.objects.filter(id=user_id)) - - if user_group: - user_group.update(name=group_name, comment=comment) - user_group.user_set.clear() - user_group.user_set = users except ServerError, e: error = e @@ -133,8 +134,8 @@ def group_edit(request): return HttpResponseRedirect('/juser/group_list/') else: users_all = User.objects.all() - users_selected = user_group.user_set.all() - users_remain = [user for user in users_all if user not in users_selected] + users_selected = User.objects.filter(group=user_group) + users_remain = User.objects.filter(~Q(group=user_group)) return my_render('juser/group_edit.html', locals(), request) From 75fbd9e615c7513f5a0e462f08430eda16b6d1ed Mon Sep 17 00:00:00 2001 From: liuzheng712 Date: Fri, 20 Nov 2015 11:08:39 +0800 Subject: [PATCH 2/5] annotation the Asset --- jumpserver/views.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/jumpserver/views.py b/jumpserver/views.py index 89bc75fd8..3f8ba2fae 100644 --- a/jumpserver/views.py +++ b/jumpserver/views.py @@ -80,18 +80,19 @@ def index_cu(request): # user = get_object(User, id=user_id) login_types = {'L': 'LDAP', 'M': 'MAP'} username = request.user.username - posts = Asset.object.all() - host_count = len(posts) - - new_posts = [] - post_five = [] - for post in posts: - if len(post_five) < 5: - post_five.append(post) - else: - new_posts.append(post_five) - post_five = [] - new_posts.append(post_five) + # TODO: need fix,liuzheng need Asset help + # posts = Asset.object.all() + # host_count = len(posts) + # + # new_posts = [] + # post_five = [] + # for post in posts: + # if len(post_five) < 5: + # post_five.append(post) + # else: + # new_posts.append(post_five) + # post_five = [] + # new_posts.append(post_five) return render_to_response('index_cu.html', locals(), context_instance=RequestContext(request)) From 4bbae381503f7a429c9d38a5defc1e653d5ce8b1 Mon Sep 17 00:00:00 2001 From: liuzheng712 Date: Fri, 20 Nov 2015 11:16:47 +0800 Subject: [PATCH 3/5] confirm alert --- templates/juser/group_list.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/templates/juser/group_list.html b/templates/juser/group_list.html index d3fdf7027..86e4ec3f6 100644 --- a/templates/juser/group_list.html +++ b/templates/juser/group_list.html @@ -93,6 +93,7 @@ type="checkbox" name="selected" value="{{ group.id }}"> $(document).ready(function(){ $('.del').click(function(){ var row = $(this).closest('tr'); + if (confirm("确定删除")) { $.get( $(this).attr('value'), {}, @@ -101,7 +102,7 @@ type="checkbox" name="selected" value="{{ group.id }}"> alert(data); } - ) + )} }); $('#del_btn').click(function(){ From f863f4b7aedbf3924846a5bbb03ecb653333abd2 Mon Sep 17 00:00:00 2001 From: liuzheng712 Date: Fri, 20 Nov 2015 11:26:07 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E7=99=BB=E9=99=86web=E7=9A=84=E5=AF=86?= =?UTF-8?q?=E7=A0=81=EF=BC=88=E5=A6=82=E4=B8=8D=E4=BF=AE=E6=94=B9=E8=AF=B7?= =?UTF-8?q?=E7=95=99=E7=A9=BA=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/juser/user_edit.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/juser/user_edit.html b/templates/juser/user_edit.html index 630468caa..5dbeb05c4 100644 --- a/templates/juser/user_edit.html +++ b/templates/juser/user_edit.html @@ -42,7 +42,7 @@
- 登陆web的密码 + 登陆web的密码(如不修改请留空)
From a88ee0725db17ef348208f71c6b8f13493cb181e Mon Sep 17 00:00:00 2001 From: yumaojun <719118794@qq.com> Date: Fri, 20 Nov 2015 14:07:17 +0800 Subject: [PATCH 5/5] =?UTF-8?q?1.=20=E5=9C=A8=E6=8E=88=E6=9D=83=E8=A7=84?= =?UTF-8?q?=E5=88=99=E6=B7=BB=E5=8A=A0=E9=A1=B5=E9=9D=A2=E3=80=80=E9=80=9A?= =?UTF-8?q?=E8=BF=87js=20=E7=BB=99=E4=BA=88=E7=94=A8=E6=88=B7=E8=BE=93?= =?UTF-8?q?=E5=85=A5=E6=8F=90=E9=86=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/jperm/perm_rule_add.html | 31 ++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/templates/jperm/perm_rule_add.html b/templates/jperm/perm_rule_add.html index 6a34cfcf4..3eef4eb00 100644 --- a/templates/jperm/perm_rule_add.html +++ b/templates/jperm/perm_rule_add.html @@ -118,6 +118,37 @@ {% endblock %} {% block self_footer_js %}