From 75979e39998a337375cea6dad9e743c2c69066dc Mon Sep 17 00:00:00 2001 From: guanghongwei Date: Sat, 7 Feb 2015 00:07:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9sudo=E6=8E=88=E6=9D=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jperm/models.py | 17 +-- jperm/urls.py | 1 + jperm/views.py | 22 ++- templates/jperm/sudo_list.html | 242 +++++++++++++++++++++++++++++++++ templates/nav.html | 2 +- 5 files changed, 270 insertions(+), 14 deletions(-) create mode 100644 templates/jperm/sudo_list.html diff --git a/jperm/models.py b/jperm/models.py index 2232689cc..083f8089d 100644 --- a/jperm/models.py +++ b/jperm/models.py @@ -11,21 +11,14 @@ class Perm(models.Model): return '%s_%s' % (self.user_group.name, self.asset_group.name) -class CMD(models.Model): - cmd = models.CharField(max_length=200) - - class CmdGroup(models.Model): name = models.CharField(max_length=50) - cmd = models.ForeignKey(CMD) + cmd = models.CharField(max_length=999) comment = models.CharField(blank=True, null=True, max_length=50) class SudoPerm(models.Model): - user = models.CharField(max_length=100) - is_user_group = models.BooleanField(default=False) - asset = models.CharField(max_length=100) - is_asset_group = models.BooleanField(default=False) - cmd = models.CharField(max_length=200) - is_cmd_group = models.BooleanField(default=False) - + user_group = models.ManyToManyField(UserGroup) + asset_group = models.ManyToManyField(BisGroup) + cmd_group = models.ManyToManyField(CmdGroup) + comment = models.CharField(max_length=30) \ No newline at end of file diff --git a/jperm/urls.py b/jperm/urls.py index 89e6c05f1..6d34810ea 100644 --- a/jperm/urls.py +++ b/jperm/urls.py @@ -12,4 +12,5 @@ urlpatterns = patterns('jperm.views', (r'^perm_detail/$', 'perm_detail'), (r'^perm_del/$', 'perm_del'), (r'^perm_asset_detail/$', 'perm_asset_detail'), + (r'^sudo_list/$', 'sudo_list'), ) diff --git a/jperm/views.py b/jperm/views.py index b0d18201e..ad30f23e5 100644 --- a/jperm/views.py +++ b/jperm/views.py @@ -4,7 +4,7 @@ from django.shortcuts import render_to_response from django.http import HttpResponseRedirect, HttpResponse from juser.models import User, UserGroup from jasset.models import Asset, BisGroup -from jperm.models import Perm +from jperm.models import Perm, SudoPerm from django.core.paginator import Paginator, EmptyPage, InvalidPage @@ -137,3 +137,23 @@ def perm_asset_detail(request): return render_to_response('jperm/perm_asset_detail.html', locals()) +def sudo_list(request): + header_title, path1, path2 = u'Sudo授权 | Perm Sudo Detail.', u'jperm', u'sudo_list' + sudo_perms = contact_list = SudoPerm.objects.all() + users = contact_list2 = User.objects.all().order_by('id') + p = paginator = Paginator(contact_list, 10) + p2 = paginator2 = Paginator(contact_list2, 10) + try: + page = int(request.GET.get('page', '1')) + except ValueError: + page = 1 + + try: + contacts = paginator.page(page) + contacts2 = paginator2.page(page) + except (EmptyPage, InvalidPage): + contacts = paginator.page(paginator.num_pages) + contacts2 = paginator2.page(paginator2.num_pages) + return render_to_response('jperm/sudo_list.html', locals()) + + diff --git a/templates/jperm/sudo_list.html b/templates/jperm/sudo_list.html new file mode 100644 index 000000000..215abbe26 --- /dev/null +++ b/templates/jperm/sudo_list.html @@ -0,0 +1,242 @@ +{% extends 'base.html' %} +{% load mytags %} +{% block content %} +{% include 'nav_cat_bar.html' %} + +
+
+
+
+
+
Sudo授权 show sudo perm info.
+ +
+ +
+
+
+
+ +
+
+ +
+ +
+
+ + + + + + + + + + + {% for sudo_perm in contacts.object_list %} + + + + + + + {% endfor %} + +
用户(组)主机(组)命令(组)操作
+ {% for user_group in sudo_perm.user_group %} + {{ user_group.name }} + {% endfor %} + + {% for asset_group in sudo_perm.asset_group %} + {{ asset_group.name }} + {% endfor %} + + {% for cmd_group in sudo_perm.cmd_group %} + {{ cmd_group.name }} + {% endfor %} + + 详情 + 编辑 + 删除 +
+
+
+
+ Showing {{ contacts.start_index }} to {{ contacts.end_index }} of {{ p.count }} entries +
+
+
+
+
    + {% if contacts.has_previous %} + + {% else %} + + {% endif %} + {% for page in p.page_range %} + {% ifequal offset1 page %} +
  • {{ page }}
  • + {% else %} +
  • {{ page }}
  • + {% endifequal %} + {% endfor %} + {% if contacts.has_next %} + + {% else %} + + {% endif %} +
+
+
+
+
+ +
+ + + + + + + + + + + + {% for user in contacts2.object_list %} + + + + + + + + {% endfor %} + +
用户角色属组主机数量操作
{{ user.name }} {{ user.id | get_role }} {{ user.username | groups_str }} {{ user.id | perm_asset_count }} + 详情 +
+
+
+
+ Showing {{ contacts2.start_index }} to {{ contacts2.end_index }} of {{ p2.count }} entries +
+
+
+
+
    + {% if contacts2.has_previous %} + + {% else %} + + {% endif %} + {% for page in p2.page_range %} + {% ifequal offset1 page %} +
  • {{ page }}
  • + {% else %} +
  • {{ page }}
  • + {% endifequal %} + {% endfor %} + {% if contacts2.has_next %} + + {% else %} + + {% endif %} +
+
+
+
+ +
+
+ +
+ +
+ + + +
+
+
+
+
+ + + +{% endblock %} \ No newline at end of file diff --git a/templates/nav.html b/templates/nav.html index e527f4ecf..50f71972e 100644 --- a/templates/nav.html +++ b/templates/nav.html @@ -33,7 +33,7 @@ 授权管理