From a8ce9e9952be1865b77c16752657714d8a80e48f Mon Sep 17 00:00:00 2001 From: ibuler Date: Wed, 21 Jan 2015 23:56:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8E=88=E6=9D=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jpermission/views.py | 31 ++++++++++++++++++++++--------- templates/jperm/perm_add.html | 9 ++++++--- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/jpermission/views.py b/jpermission/views.py index c3d5e59fc..bdd27a3fa 100644 --- a/jpermission/views.py +++ b/jpermission/views.py @@ -4,6 +4,7 @@ from django.shortcuts import render_to_response from django.http import HttpResponseRedirect from juser.models import User from jasset.models import Asset +from jpermission.models import Permission def perm_user_list(request): @@ -14,16 +15,28 @@ def perm_user_list(request): def perm_add(request): header_title, path1, path2 = u'添加授权 | Add User perm.', u'授权管理', u'添加授权' - username = request.GET.get('username', None) - if not username: - return HttpResponseRedirect('/') + if request.method == 'GET': + username = request.GET.get('username', None) + if not username: + return HttpResponseRedirect('/') - user = User.objects.get(username=username) - permed_hosts = [] - for perm in user.permission_set.all(): - permed_hosts.append(perm.asset) + user = User.objects.get(username=username) + permed_hosts = [] + for perm in user.permission_set.all(): + permed_hosts.append(perm.asset) - hosts_all = Asset.objects.all() - hosts = list(set(hosts_all) - set(permed_hosts)) + hosts_all = Asset.objects.all() + hosts = list(set(hosts_all) - set(permed_hosts)) + + else: + username = request.POST.get('username', None) + host_ips = request.POST.getlist('host_ips', None) + + user = User.objects.get(username=username) + for ip in host_ips: + asset = Asset.objects.get(ip=ip) + perm = Permission(user=user, asset=asset) + perm.save() + msg = u'添加成功' return render_to_response('jperm/perm_add.html', locals()) \ No newline at end of file diff --git a/templates/jperm/perm_add.html b/templates/jperm/perm_add.html index dcfde9f25..d4b2a75c8 100644 --- a/templates/jperm/perm_add.html +++ b/templates/jperm/perm_add.html @@ -37,14 +37,17 @@ {% endif %}
- +
+
+
+
+ - {% for host in hosts %} - {% endfor %}