From 56f8f5d09bf438301497d288be2df92fd7e516d0 Mon Sep 17 00:00:00 2001 From: guanghongwei Date: Sun, 15 Feb 2015 10:06:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=86=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jperm/urls.py | 3 +- jperm/views.py | 17 +- jumpserver/views.py | 8 + juser/views.py | 18 +- templates/jperm/perm_list.html | 132 +++++++------- templates/jperm/perm_user_detail.html | 240 ++++++++++++++++++++++++++ templates/juser/user_list.html | 4 +- 7 files changed, 339 insertions(+), 83 deletions(-) create mode 100644 templates/jperm/perm_user_detail.html diff --git a/jperm/urls.py b/jperm/urls.py index 4f8819f23..dd44e21b4 100644 --- a/jperm/urls.py +++ b/jperm/urls.py @@ -9,7 +9,8 @@ urlpatterns = patterns('jperm.views', (r'^perm_edit/$', 'perm_edit'), (r'^perm_add/$', 'perm_add'), (r'^perm_list/$', 'perm_list'), - (r'^perm_list_ajax/$', 'perm_list_ajax'), + (r'^perm_user_detail/$', 'perm_user_detail'), + # (r'^perm_list_ajax/$', 'perm_list_ajax'), (r'^perm_detail/$', 'perm_detail'), (r'^perm_del/$', 'perm_del'), (r'^perm_asset_detail/$', 'perm_asset_detail'), diff --git a/jperm/views.py b/jperm/views.py index e577af3fc..b34ddd67d 100644 --- a/jperm/views.py +++ b/jperm/views.py @@ -7,7 +7,7 @@ from jasset.models import Asset, BisGroup from jperm.models import Perm, SudoPerm, CmdGroup from django.core.paginator import Paginator, EmptyPage, InvalidPage from django.db.models import Q -from jumpserver.views import LDAP_ENABLE, ldap_conn, CONF, perm_user_asset +from jumpserver.views import LDAP_ENABLE, ldap_conn, CONF, perm_user_asset, page_list_return if LDAP_ENABLE: @@ -39,21 +39,24 @@ def perm_list(request): groups = contact_list = Perm.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')) + current_page = int(request.GET.get('page', '1')) except ValueError: - page = 1 + current_page = 1 + + page_range = page_list_return(len(p.page_range), current_page) try: - contacts = paginator.page(page) - contacts2 = paginator2.page(page) + contacts = paginator.page(current_page) except (EmptyPage, InvalidPage): contacts = paginator.page(paginator.num_pages) - contacts2 = paginator2.page(paginator2.num_pages) return render_to_response('jperm/perm_list.html', locals()) +def perm_user_detail(request): + header_title, path1, path2 = u'用户授权详情 | Perm User Detail.', u'授权管理', u'授权详情' + + def user_asset_cmd_groups_get(user_groups_select='', asset_groups_select='', cmd_groups_select=''): user_groups_select_list = [] asset_groups_select_list = [] diff --git a/jumpserver/views.py b/jumpserver/views.py index dd2510ccc..d73fcd316 100644 --- a/jumpserver/views.py +++ b/jumpserver/views.py @@ -50,6 +50,14 @@ def jasset_group_add(name, comment, type): class ServerError(Exception): pass + +def page_list_return(total, current=1): + min_page = current - 2 if current - 4 > 0 else 1 + max_page = min_page + 4 if min_page + 4 < total else total + + return range(min_page, max_page+1) + + def jasset_host_edit(j_id, j_ip, j_idc, j_port, j_type, j_group, j_active, j_comment): groups = [] is_active = {u'是': '1', u'否': '2'} diff --git a/juser/views.py b/juser/views.py index d2073d553..c810b568c 100644 --- a/juser/views.py +++ b/juser/views.py @@ -20,7 +20,7 @@ from juser.models import UserGroup, User from connect import PyCrypt, KEY from connect import BASE_DIR from connect import CONF -from jumpserver.views import md5_crypt, LDAPMgmt, LDAP_ENABLE, ldap_conn +from jumpserver.views import md5_crypt, LDAPMgmt, LDAP_ENABLE, ldap_conn, page_list_return if LDAP_ENABLE: LDAP_HOST_URL = CONF.get('ldap', 'host_url') @@ -265,12 +265,14 @@ def group_list(request): p = paginator = Paginator(contact_list, 10) try: - page = int(request.GET.get('page', '1')) + current_page = int(request.GET.get('page', '1')) except ValueError: - page = 1 + current_page = 1 + + page_range = page_list_return(len(p.page_range), current_page) try: - contacts = paginator.page(page) + contacts = paginator.page(current_page) except (EmptyPage, InvalidPage): contacts = paginator.page(paginator.num_pages) return render_to_response('juser/group_list.html', locals()) @@ -333,12 +335,14 @@ def user_list(request): p = paginator = Paginator(contact_list, 10) try: - page = int(request.GET.get('page', '1')) + current_page = int(request.GET.get('page', '1')) except ValueError: - page = 1 + current_page = 1 + + page_range = page_list_return(len(p.page_range), current_page) try: - contacts = paginator.page(page) + contacts = paginator.page(current_page) except (EmptyPage, InvalidPage): contacts = paginator.page(paginator.num_pages) return render_to_response('juser/user_list.html', locals()) diff --git a/templates/jperm/perm_list.html b/templates/jperm/perm_list.html index c4c9fcbd9..aef677c80 100644 --- a/templates/jperm/perm_list.html +++ b/templates/jperm/perm_list.html @@ -33,8 +33,8 @@
- - - - - - - - - - - - {% 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 %} -
-
-
-
+{# #} +{# #} +{# #} +{# #} +{# #} +{# #} +{# #} +{# #} +{# #} +{# #} +{# #} +{# {% 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 page_range2 %}#} +{# {% ifequal current_page page %}#} +{#
  • {{ page }}
  • #} +{# {% else %}#} +{#
  • {{ page }}
  • #} +{# {% endifequal %}#} +{# {% endfor %}#} +{# {% if contacts2.has_next %}#} +{# #} +{# {% else %}#} +{# #} +{# {% endif %}#} +{#
#} +{#
#} +{#
#} +{#
#}
diff --git a/templates/jperm/perm_user_detail.html b/templates/jperm/perm_user_detail.html new file mode 100644 index 000000000..aef677c80 --- /dev/null +++ b/templates/jperm/perm_user_detail.html @@ -0,0 +1,240 @@ +{% extends 'base.html' %} +{% load mytags %} +{% block content %} +{% include 'nav_cat_bar.html' %} + +
+
+
+
+
+
用户组授权 show host perm info.
+ +
+ +
+
+
+
+ +
+
+ +
+ +
+
+ + + + + + + + + + + + {% for perm in contacts.object_list %} + + + + + + + + {% endfor %} + +
名称用户组主机组备注操作
{{ perm.name }} + {% for user_group in perm.user_group.all %} + {{ user_group.name }} + {% endfor %} + + {% for asset_group in perm.asset_group.all %} + {{ asset_group.name }} + {% endfor %} + {{ perm.comment }} + 详情 + 编辑 + 删除 +
+
+
+
+ Showing {{ contacts.start_index }} to {{ contacts.end_index }} of {{ p.count }} entries +
+
+
+
+
    + {% if contacts.has_previous %} + + {% else %} + + {% endif %} + {% for page in page_range %} + {% ifequal current_page 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 page_range2 %}#} +{# {% ifequal current_page page %}#} +{#
  • {{ page }}
  • #} +{# {% else %}#} +{#
  • {{ page }}
  • #} +{# {% endifequal %}#} +{# {% endfor %}#} +{# {% if contacts2.has_next %}#} +{# #} +{# {% else %}#} +{# #} +{# {% endif %}#} +{#
#} +{#
#} +{#
#} +{#
#} + +
+
+ +
+ +
+ + + +
+
+
+
+
+ + + +{% endblock %} \ No newline at end of file diff --git a/templates/juser/user_list.html b/templates/juser/user_list.html index 3855a786e..2fdf613b3 100644 --- a/templates/juser/user_list.html +++ b/templates/juser/user_list.html @@ -89,8 +89,8 @@ Previous {% endif %} - {% for page in p.page_range %} - {% ifequal offset1 page %} + {% for page in page_range %} + {% ifequal current_page page %}
  • {{ page }}
  • {% else %}
  • {{ page }}