From e78d7b0219fcc63101c215f5c1e0f2e15a816c99 Mon Sep 17 00:00:00 2001 From: wangyong <864072399@qq.com> Date: Sun, 6 Dec 2015 23:48:39 +0800 Subject: [PATCH] cu asset page and sth --- jasset/asset_api.py | 4 +- jasset/views.py | 24 +- templates/jasset/asset_cu_list.html | 388 ++++++++++++++++++++++++++++ templates/jasset/asset_list.html | 14 +- 4 files changed, 414 insertions(+), 16 deletions(-) create mode 100644 templates/jasset/asset_cu_list.html diff --git a/jasset/asset_api.py b/jasset/asset_api.py index bf2b93923..c3c966965 100644 --- a/jasset/asset_api.py +++ b/jasset/asset_api.py @@ -213,8 +213,8 @@ def write_excel(asset_all): group_all = '/'.join(group_list) status = asset.get_status_display() idc_name = asset.idc.name if asset.idc else u'' - system_type = asset.system_type if asset.idc else u'' - system_version = asset.system_version if asset.idc else u'' + system_type = asset.system_type if asset.system_type else u'' + system_version = asset.system_version if asset.system_version else u'' system_os = unicode(system_type) + unicode(system_version) alter_dic = [asset.hostname, asset.ip, idc_name, group_all, system_os, asset.cpu, asset.memory, diff --git a/jasset/views.py b/jasset/views.py index ea0c1ccf9..9eaa8beef 100644 --- a/jasset/views.py +++ b/jasset/views.py @@ -6,9 +6,7 @@ from jumpserver.api import * from jumpserver.models import Setting from jasset.forms import AssetForm, IdcForm from jasset.models import Asset, IDC, AssetGroup, ASSET_TYPE, ASSET_STATUS -from jperm.perm_api import get_group_asset_perm -from jperm.ansible_api import MyRunner -from jperm.perm_api import gen_resource +from jperm.perm_api import get_group_asset_perm, get_group_user_perm @require_role('admin') @@ -169,7 +167,7 @@ def asset_add(request): @require_role('admin') def asset_add_batch(request): header_title, path1, path2 = u'添加资产', u'资产管理', u'批量添加' - return my_render('jasset/asset_add_batch.html', locals(), request) + return my_render('jasset/server_add_batch.html', locals(), request) @require_role('admin') @@ -259,6 +257,8 @@ def asset_list(request): asset list view """ header_title, path1, path2 = u'查看资产', u'资产管理', u'查看资产' + username = request.user.username + user_perm = request.session['role_id'] idc_all = IDC.objects.filter() asset_group_all = AssetGroup.objects.all() asset_types = ASSET_TYPE @@ -282,12 +282,19 @@ def asset_list(request): if idc: asset_find = Asset.objects.filter(idc=idc) else: - asset_find = Asset.objects.all() + if user_perm != 0: + asset_find = Asset.objects.all() + else: + user = get_object(User, username=username) + asset_perm = get_group_user_perm(user) if user else {'asset': ''} + asset_find = asset_perm['asset'].keys() + asset_group_all = list(asset_perm['asset_group']) if idc_name: asset_find = asset_find.filter(idc__name__contains=idc_name) if group_name: + print asset_find, type(asset_find) asset_find = asset_find.filter(group__name__contains=group_name) if asset_type: @@ -324,7 +331,10 @@ def asset_list(request): smg = u'excel文件已生成,请点击下载!' return my_render('jasset/asset_excel_download.html', locals(), request) assets_list, p, assets, page_range, current_page, show_first, show_end = pages(asset_find, request) - return my_render('jasset/asset_list.html', locals(), request) + if user_perm != 0: + return my_render('jasset/asset_list.html', locals(), request) + else: + return my_render('jasset/asset_cu_list.html', locals(), request) @require_role('admin') @@ -551,4 +561,4 @@ def asset_upload(request): smg = u'批量添加成功' else: emg = u'批量添加失败,请检查格式.' - return my_render('jasset/asset_add_batch.html', locals(), request) + return my_render('jasset/server_add_batch.html', locals(), request) diff --git a/templates/jasset/asset_cu_list.html b/templates/jasset/asset_cu_list.html new file mode 100644 index 000000000..9d1dd7bf9 --- /dev/null +++ b/templates/jasset/asset_cu_list.html @@ -0,0 +1,388 @@ +{% extends 'base.html' %} +{% load mytags %} +{% block content %} +{% include 'nav_cat_bar.html' %} + +
+
+
+
+
+
主机详细信息列表
+ +
+ +
+
+
+ + + + + + + +
+ +
+
+ + +
+ + +
+
+
+
+ + + + + + + + +{# #} + + + + + + + + + {% for asset in assets.object_list %} + + + + + + +{# #} + + + + + + + {% endfor %} + +
+ + 主机名 IP地址 IDC 所属主机组 配置信息 操作系统 cpu核数 内存 硬盘 操作
+ + {{ asset.hostname|default_if_none:"" }} {{ asset.ip|default_if_none:"" }} {{ asset.idc.name|default_if_none:"" }} {{ asset.group.all|group_str2 }}{{ asset.cpu }}|{{ asset.memory }}|{{ asset.disk }}{{ asset.system_type|default_if_none:"" }}{{ asset.system_version|default_if_none:"" }} {{ asset.cpu|get_cpu_core|default_if_none:"" }} {{ asset.memory }}{% if asset.memory %}G{% endif %} {{ asset.disk|get_disk_info }}{% if asset.memory %}G{% endif %} + 连接 +
+
+
+ +
+ {% include 'paginator.html' %} +
+
+
+
+
+
+
+{% endblock %} + +{% block self_footer_js %} + + +{% endblock %} \ No newline at end of file diff --git a/templates/jasset/asset_list.html b/templates/jasset/asset_list.html index 6f7e856cd..834a599f6 100644 --- a/templates/jasset/asset_list.html +++ b/templates/jasset/asset_list.html @@ -30,7 +30,7 @@