From 5bf66ca92e8d29051d6f0bd38cfad0914c5845b0 Mon Sep 17 00:00:00 2001 From: halcyon <864072399@qq.com> Date: Sat, 7 Mar 2015 17:37:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=90=84=E7=A7=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/AddUserAsset.py | 12 +++---- jasset/urls.py | 4 +-- jasset/views.py | 14 +++++--- jumpserver.conf | 2 +- jumpserver/views.py | 13 +++++-- templates/jasset/group_add.html | 7 ---- templates/jasset/group_list.html | 60 ++++++++++++++++++++++++++------ templates/jasset/host_list.html | 9 +++-- templates/jasset/idc_add.html | 6 ---- templates/jasset/idc_list.html | 58 ++++++++++++++++++++++++------ templates/jasset/jlist_ip.html | 23 ++++++++---- templates/nav.html | 6 ++-- 12 files changed, 155 insertions(+), 59 deletions(-) diff --git a/docs/AddUserAsset.py b/docs/AddUserAsset.py index b9fabc291..e53772d83 100644 --- a/docs/AddUserAsset.py +++ b/docs/AddUserAsset.py @@ -108,14 +108,12 @@ def test_add_log(): if __name__ == '__main__': - #test_add_dept() - #test_add_group() - #test_add_user() - #test_add_idc() - #test_add_asset_group() - test_add_asset() - + test_add_dept() + test_add_group() test_add_user() + test_add_idc() + test_add_asset_group() + test_add_asset() test_add_log() diff --git a/jasset/urls.py b/jasset/urls.py index f6c2d9701..386538a74 100644 --- a/jasset/urls.py +++ b/jasset/urls.py @@ -13,9 +13,9 @@ urlpatterns = patterns('', url(r'^idc_list/$', list_idc), url(r'^idc_detail/$', detail_idc), url(r'^idc_del/(\d+)/$', del_idc), - url(r'^group_add/$', add_group), + url(r'^jgroup_add/$', add_group), url(r'^group_edit/$', edit_group), - url(r'^group_list/$', list_group), + url(r'^jgroup_list/$', list_group), url(r'^group_detail/$', detail_group), url(r'^group_del_host/(\w+)/$', group_del_host), url(r'^group_del/(\d+)/$', group_del), diff --git a/jasset/views.py b/jasset/views.py index 179b7ad5f..1c94a49ee 100644 --- a/jasset/views.py +++ b/jasset/views.py @@ -10,6 +10,7 @@ from juser.models import UserGroup from connect import PyCrypt, KEY from jlog.models import Log from jumpserver.views import jasset_group_add, jasset_host_edit, pages +from jumpserver.api import asset_perm_api cryptor = PyCrypt(KEY) @@ -143,7 +144,7 @@ def list_host(request): header_title, path1, path2 = u'查看主机', u'资产管理', u'查看主机' login_types = {'L': 'LDAP', 'S': 'SSH_KEY', 'P': 'PASSWORD', 'M': 'MAP'} posts = Asset.objects.all().order_by('ip') - contact_list, p, contacts, page_range, current_page = pages(posts, request) + contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(posts, request) return render_to_response('jasset/host_list.html', locals(), context_instance=RequestContext(request)) @@ -223,6 +224,7 @@ def jlist_ip(request, offset): login_types = {'L': 'LDAP', 'S': 'SSH_KEY', 'P': 'PASSWORD', 'M': 'MAP'} post = contact_list = Asset.objects.get(ip=str(offset)) log = Log.objects.filter(host=str(offset)) + user_permed_list = asset_perm_api(Asset.objects.get(ip=str(offset))) return render_to_response('jasset/jlist_ip.html', locals(), context_instance=RequestContext(request)) @@ -244,6 +246,8 @@ def add_idc(request): def list_idc(request): header_title, path1, path2 = u'查看IDC', u'资产管理', u'查看IDC' posts = IDC.objects.all().order_by('id') + contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(posts, request) + print contact_list, p, contacts, page_range, current_page, show_first, show_end return render_to_response('jasset/idc_list.html', locals(), context_instance=RequestContext(request)) @@ -277,6 +281,8 @@ def add_group(request): def list_group(request): header_title, path1, path2 = u'查看主机组', u'资产管理', u'查看主机组' posts = BisGroup.objects.filter(type='A').order_by('id') + contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(posts, request) + return render_to_response('jasset/group_list.html', locals(), context_instance=RequestContext(request)) @@ -310,7 +316,7 @@ def detail_group(request): group_name = BisGroup.objects.get(id=group_id).name b = BisGroup.objects.get(id=group_id) posts = Asset.objects.filter(bis_group=b).order_by('ip') - contact_list, p, contacts, page_range, current_page = pages(posts, request) + contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(posts, request) return render_to_response('jasset/group_detail.html', locals(), context_instance=RequestContext(request)) @@ -322,7 +328,7 @@ def detail_idc(request): idc_name = IDC.objects.get(id=idc_id).name b = IDC.objects.get(id=idc_id) posts = Asset.objects.filter(idc=b).order_by('ip') - contact_list, p, contacts, page_range, current_page = pages(posts, request) + contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(posts, request) return render_to_response('jasset/idc_detail.html', locals(), context_instance=RequestContext(request)) @@ -359,7 +365,7 @@ def host_search(request): posts = Asset.objects.filter(Q(ip__contains=keyword) | Q(idc__name__contains=keyword) | Q(bis_group__name__contains=keyword) | Q( comment__contains=keyword)).distinct().order_by('ip') - contact_list, p, contacts, page_range, current_page = pages(posts, request) + contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(posts, request) return render_to_response('jasset/host_search.html', locals(), context_instance=RequestContext(request)) diff --git a/jumpserver.conf b/jumpserver.conf index a24c2190a..9540fa014 100644 --- a/jumpserver.conf +++ b/jumpserver.conf @@ -8,7 +8,7 @@ password = mysql234 database = jumpserver [ldap] -ldap_enable = 1 +ldap_enable = 0 host_url = ldap://127.0.0.1:389 base_dn = dc=jumpserver, dc=org root_dn = cn=admin,dc=jumpserver,dc=org diff --git a/jumpserver/views.py b/jumpserver/views.py index 1e2a00fa6..544bf34f5 100644 --- a/jumpserver/views.py +++ b/jumpserver/views.py @@ -166,7 +166,7 @@ def jasset_host_edit(j_id, j_ip, j_idc, j_port, j_type, j_group, j_active, j_com def pages(posts, r): """分页公用函数""" contact_list = posts - p = paginator = Paginator(contact_list, 20) + p = paginator = Paginator(contact_list, 10) try: current_page = int(r.GET.get('page', '1')) except ValueError: @@ -179,7 +179,16 @@ def pages(posts, r): except (EmptyPage, InvalidPage): contacts = paginator.page(paginator.num_pages) - return contact_list, p, contacts, page_range, current_page + if current_page >= 5: + show_first = 1 + else: + show_first = 0 + if current_page <= (len(p.page_range) - 3): + show_end = 1 + else: + show_end = 0 + + return contact_list, p, contacts, page_range, current_page, show_first, show_end def login(request): diff --git a/templates/jasset/group_add.html b/templates/jasset/group_add.html index 1f2d07edb..e926af296 100644 --- a/templates/jasset/group_add.html +++ b/templates/jasset/group_add.html @@ -4,13 +4,6 @@
- -
填写主机组基本信息
diff --git a/templates/jasset/group_list.html b/templates/jasset/group_list.html index 89c9d508f..3f54241e2 100644 --- a/templates/jasset/group_list.html +++ b/templates/jasset/group_list.html @@ -5,22 +5,17 @@
-
+
- + @@ -28,9 +23,9 @@ - {% for post in posts %} + {% for post in contacts.object_list %} - + @@ -43,6 +38,51 @@ {% endfor %}
ID 主机组名 主机数量 备注
{{ post.id }} {{ post.name }} {{ post.asset_set.count }} {{ post.comment }}
+
+
+ + +
+
+
+
    + + {% if contacts.has_previous %} + + {% else %} + + {% endif %} + {% ifequal show_first 1 %} +
  • 1...
  • + {% endifequal %} + {% for page in page_range %} + {% ifequal current_page page %} +
  • {{ page }}
  • + {% else %} +
  • {{ page }}
  • + {% endifequal %} + {% endfor %} + {% ifequal show_end 1 %} +
  • ...{{ p.num_pages }}
  • + {% endifequal %} + {% if contacts.has_next %} + + {% else %} + + {% endif %} +
+
+
+
+
diff --git a/templates/jasset/host_list.html b/templates/jasset/host_list.html index 7be40d80f..14a4810d1 100644 --- a/templates/jasset/host_list.html +++ b/templates/jasset/host_list.html @@ -8,7 +8,7 @@
-
主机详细信息列表
+
主机详细信息列表
@@ -99,6 +99,9 @@ Previous {% endif %} + {% ifequal show_first 1 %} +
  • 1...
  • + {% endifequal %} {% for page in page_range %} {% ifequal current_page page %}
  • {{ page }}
  • @@ -106,7 +109,9 @@
  • {{ page }}
  • {% endifequal %} {% endfor %} -
  • ...{{ p.num_pages }}
  • + {% ifequal show_end 1 %} +
  • ...{{ p.num_pages }}
  • + {% endifequal %} {% if contacts.has_next %}