diff --git a/jpermission/urls.py b/jpermission/urls.py index 39256ca7f..60fe5446c 100644 --- a/jpermission/urls.py +++ b/jpermission/urls.py @@ -6,7 +6,7 @@ urlpatterns = patterns('jpermission.views', # url(r'^$', 'jumpserver.views.home', name='home'), # url(r'^blog/', include('blog.urls')), - (r'^perm_user_list/$', 'perm_user_list'), + (r'^perm_host/$', 'perm_host'), (r'^perm_add/$', 'perm_add'), (r'^perm_user_show/$', 'perm_user_show'), (r'^perm_list/$', 'perm_list'), diff --git a/jpermission/views.py b/jpermission/views.py index 8da55a238..174b1f9a6 100644 --- a/jpermission/views.py +++ b/jpermission/views.py @@ -5,12 +5,23 @@ 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): - header_title, path1, path2 = u'查看授权用户 | Perm User Detail.', u'授权管理', u'用户详情' - users = User.objects.all() - return render_to_response('jperm/perm_user_list.html', locals(),) +from django.core.paginator import Paginator, EmptyPage, InvalidPage + + +def perm_host(request): + header_title, path1, path2 = u'主机授权 | Perm Host Detail.', u'jperm', u'perm_host' + users = contact_list = User.objects.all().order_by('id') + p = paginator = Paginator(contact_list, 10) + try: + page = int(request.GET.get('page', '1')) + except ValueError: + page = 1 + + try: + contacts = paginator.page(page) + except (EmptyPage, InvalidPage): + contacts = paginator.page(paginator.num_pages) + return render_to_response('jperm/perm_host.html', locals(),) def perm_add(request): diff --git a/jumpserver/templatetags/mytags.py b/jumpserver/templatetags/mytags.py index 4c4045254..d33858277 100644 --- a/jumpserver/templatetags/mytags.py +++ b/jumpserver/templatetags/mytags.py @@ -45,4 +45,9 @@ def bool2str(value): if value: return u'是' else: - return u'否' \ No newline at end of file + return u'否' + +@register.filter(name='perm_total') +def perm_total(user_id): + user = User.objects.get(int(user_id)) + return user.permission_set.all().count() \ No newline at end of file diff --git a/templates/jperm/perm_host.html b/templates/jperm/perm_host.html new file mode 100644 index 000000000..d2f8753b0 --- /dev/null +++ b/templates/jperm/perm_host.html @@ -0,0 +1,111 @@ +{% extends 'base.html' %} +{% load mytags %} +{% block content %} +{% include 'nav_cat_bar.html' %} + +
用户名 | +姓名 | +属组 | +授权总数 | +操作 | +
---|---|---|---|---|
{{ user.username }} | +{{ user.name }} | +{{ user.username|groups_str }} | +{{ user.id|perm_count }} | ++ 详情 + 编辑 + | +