Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
gjl2004yn
jumpserver
提交
73f5891f
J
jumpserver
项目概览
gjl2004yn
/
jumpserver
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jumpserver
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
73f5891f
编写于
10月 12, 2016
作者:
江
江世峰
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
asset:update assets_list by tag
上级
b99b88a3
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
681 addition
and
87 deletion
+681
-87
apps/assets/api.py
apps/assets/api.py
+0
-1
apps/assets/forms.py
apps/assets/forms.py
+1
-3
apps/assets/templates/assets/asset_list.html
apps/assets/templates/assets/asset_list.html
+203
-67
apps/assets/templates/assets/asset_tag_create.html
apps/assets/templates/assets/asset_tag_create.html
+118
-0
apps/assets/templates/assets/asset_tag_detail.html
apps/assets/templates/assets/asset_tag_detail.html
+219
-0
apps/assets/templates/assets/asset_tags_list.html
apps/assets/templates/assets/asset_tags_list.html
+56
-0
apps/assets/templatetags/asset_tags.py
apps/assets/templatetags/asset_tags.py
+6
-0
apps/assets/templatetags/example_tags.py
apps/assets/templatetags/example_tags.py
+0
-0
apps/assets/utils.py
apps/assets/utils.py
+34
-1
apps/assets/views.py
apps/assets/views.py
+15
-11
apps/common/templatetags/common_tags.py
apps/common/templatetags/common_tags.py
+4
-0
apps/static/css/jumpserver.css
apps/static/css/jumpserver.css
+19
-0
apps/static/css/plugins/inputTags.css
apps/static/css/plugins/inputTags.css
+2
-2
apps/templates/_base_list.html
apps/templates/_base_list.html
+4
-2
未找到文件。
apps/assets/api.py
浏览文件 @
73f5891f
...
...
@@ -51,4 +51,3 @@ class IDCViewSet(viewsets.ReadOnlyModelViewSet):
queryset
=
IDC
.
objects
.
all
()
serializer_class
=
IDCSerializer
apps/assets/forms.py
浏览文件 @
73f5891f
...
...
@@ -26,12 +26,10 @@ class AssetCreateForm(forms.ModelForm):
def
__init__
(
self
,
*
args
,
**
kwargs
):
instance
=
kwargs
.
get
(
'instance'
,
None
)
if
instance
:
initial
=
kwargs
.
get
(
'initial'
,
{})
tags
=
instance
.
tags
.
all
()
#
tags = instance.tags.all()
initial
[
'tags'
]
=
[
t
.
pk
for
t
in
kwargs
[
'instance'
].
tags
.
all
()]
print
(
kwargs
.
get
(
'initial'
))
super
(
AssetCreateForm
,
self
).
__init__
(
*
args
,
**
kwargs
)
def
_save_m2m
(
self
):
...
...
apps/assets/templates/assets/asset_list.html
浏览文件 @
73f5891f
{% extends '_base_list.html' %}
{% extends 'base.html' %}
{% load static %}
{% load i18n %}
{% load common_tags %}
{% block content_left_head %}
<a
href=
"{% url 'assets:asset-create' %}"
class=
"btn btn-sm btn-primary "
>
{% trans "Create asset" %}
</a>
{% block custom_head_css_js %}
<link
href=
"{% static "
css
/
plugins
/
dataTables
/
dataTables.min.css
"
%}"
rel=
"stylesheet"
>
<link
href=
"{% static "
css
/
plugins
/
awesome-bootstrap-checkbox
/
awesome-bootstrap-checkbox.css
"
%}"
rel=
"stylesheet"
>
<link
href=
"{% static "
css
/
plugins
/
select2
/
select2.min.css
"
%}"
rel=
"stylesheet"
>
<script
src=
"{% static "
js
/
plugins
/
select2
/
select2.full.min.js
"
%}"
></script>
<script
src=
"{% static "
js
/
plugins
/
dataTables
/
dataTables.min.js
"
%}"
></script>
{% endblock %}
{% block table_head %}
<th
class=
"text-center"
>
<input
type=
"checkbox"
id=
"check_all"
onclick=
"checkAll('check_all', 'checked')"
>
</th>
<th
class=
"text-center"
><a
href=
"{% url 'assets:asset-list' %}?sort=hostname"
>
{% trans 'Hostname' %}
</a></th>
<th
class=
"text-center"
><a
href=
"{% url 'assets:asset-list' %}?sort=username"
>
{% trans 'IP' %}
</a></th>
<th
class=
"text-center"
>
{% trans 'Port' %}
</th>
<th
class=
"text-center"
>
{% trans 'Type' %}
</th>
<th
class=
"text-center"
>
{% trans 'Hardware' %}
</th>
<th
class=
"text-center"
>
{% trans 'Valid' %}
</th>
<th
class=
"text-center"
></th>
{% endblock %}
{% block table_body %}
{% for asset in asset_list %}
<tr
class=
"gradeX"
>
<td
class=
"text-center"
>
<input
type=
"checkbox"
name=
"checked"
value=
"{{ asset.id }}"
>
</td>
<td
class=
"text-center"
>
<a
href=
"{% url 'assets:asset-detail' pk=user.id %}"
>
{{ asset.hostname }}
</a>
</td>
<td
class=
"text-center"
>
{{ asset.ip }}
</td>
<td
class=
"text-center"
>
{{ asset.port }}
</td>
<td
class=
"text-center"
>
{{ asset.type }}
</td>
<td
class=
"text-center"
>
{{ asset.cpu }} {{ asset.memory }} {{ asset.disk }}
</td>
<td
class=
"text-center"
>
{% if asset.is_valid.0 %}
<i
class=
"fa fa-check text-navy"
></i>
{% else %}
<i
class=
"fa fa-times text-danger"
></i>
{% endif %}
</td>
<td
class=
"text-center"
>
<a
href=
"{% url 'assets:asset-update' pk=asset.id %}"
class=
"btn btn-xs btn-info"
>
{% trans 'Update' %}
</a>
<a
href=
"{% url 'assets:asset-delete' pk=asset.id %}"
class=
"btn btn-xs btn-danger del"
>
{% trans 'Delete' %}
</a>
</td>
</tr>
{% endfor %}
{% block content %}
<div
class=
"wrapper wrapper-content animated fadeInRight"
>
<div
class=
"row"
>
<div
class=
"col-sm-12"
>
<div
class=
"ibox float-e-margins"
>
<div
class=
"ibox-title"
>
<div
class=
"ibox-tools"
>
<div
style=
"float:left"
>
<a
href=
"{% url 'assets:asset-create' %}"
class=
"btn btn-sm btn-primary "
>
{% trans "Create asset" %}
</a>
</div>
<button
class=
"btn btn-sm btn-primary"
id=
"zksx"
onclick=
"tagShow()"
>
标签
</button>
<a
class=
"collapse-link"
><i
class=
"fa fa-chevron-up"
></i></a>
<a
class=
"dropdown-toggle"
data-toggle=
"dropdown"
href=
"#"
><i
class=
"fa fa-wrench"
></i></a>
<a
class=
"close-link"
><i
class=
"fa fa-times"
></i></a>
</div>
</div>
<div
class=
"ibox-content"
>
<div
class=
""
>
<div
class=
"ydxbd"
id=
"ydxbd"
style=
"display: none;"
>
<div>
<p
id=
"tags_p"
>
{% for tag in tag_list %}
<a
href=
"{% url 'assets:asset-tags' tag_id=tag.0 %}"
{%
if
tag.0
|
IntToStr =
=
tag_id
%}
class=
"fa fa-tag btn btn-sm btn-primary mar-j"
name=
"tag_on"
>
{% else %}
class="fa fa-tag btn btn-sm btn-outline btn-primary mar-j">
{% endif %}
<span
class=
"mar"
>
<strong>
{{ tag.1}}
</strong>
({{ tag.2 }})
</span></a>
{% endfor %}
<a
href=
"{% url 'assets:asset-list' %}"
class=
"btn btn-sm btn-outline btn-default "
>
移除选择
</a>
</p>
</div>
</div>
{% block content_left_head %}{% endblock %}
{% block table_search %}{% endblock %}
</div>
{% block table_container %}
<table
aria-describedby=
"editable_info"
role=
"grid"
class=
"table table-striped table-bordered table-hover dataTable"
id=
"editable"
>
<thead>
<tr>
<th
class=
"text-center"
><input
type=
"checkbox"
id=
"check_all"
onclick=
"checkAll()"
></th>
<th
class=
"text-center"
><a
href=
"{% url 'assets:asset-list' %}?sort=hostname"
>
{% trans 'Hostname' %}
</a></th>
<th
class=
"text-center"
><a
href=
"{% url 'assets:asset-list' %}?sort=username"
>
{% trans 'IP' %}
</a></th>
<th
class=
"text-center"
>
{% trans 'Port' %}
</th>
<th
class=
"text-center"
>
{% trans 'Type' %}
</th>
<th
class=
"text-center"
>
{% trans 'Hardware' %}
</th>
<th
class=
"text-center"
>
{% trans 'Valid' %}
</th>
<th
class=
"text-center"
></th>
</tr>
</thead>
<tbody>
{% for asset in asset_list %}
<tr
class=
"gradeX"
name=
"oAssets"
>
<td
class=
"text-center"
><input
type=
"checkbox"
name=
"checked"
value=
"{{ asset.id }}"
></td>
<td
class=
"text-center"
><a
href=
"{% url 'assets:asset-detail' pk=asset.id %}"
>
{{ asset.hostname }}
</a></td>
<td
class=
"text-center"
>
{{ asset.ip }}
</td>
<td
class=
"text-center"
>
{{ asset.port }}
</td>
<td
class=
"text-center"
>
{{ asset.type }}
</td>
<td
class=
"text-center"
>
{{ asset.cpu }} {{ asset.memory }} {{ asset.disk }}
</td>
<td
class=
"text-center"
>
{% if asset.is_valid.0 %}
<i
class=
"fa fa-check text-navy"
></i>
{% else %}
<i
class=
"fa fa-times text-danger"
></i>
{% endif %}
</td>
<td
class=
"text-center"
>
<a
href=
"{% url 'assets:asset-update' pk=asset.id %}"
class=
"btn btn-xs btn-info"
>
{% trans 'Update' %}
</a>
<a
href=
"{% url 'assets:asset-delete' pk=asset.id %}"
class=
"btn btn-xs btn-danger del"
>
{% trans 'Delete' %}
</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
{% block content_bottom_left %}
<form
id=
""
method=
"get"
action=
""
class=
" mail-search"
>
<div
class=
"input-group"
>
<select
class=
"form-control m-b"
style=
"width: auto"
>
<option>
{% trans 'Delete selected' %}
</option>
<option>
{% trans 'Update selected' %}
</option>
<option>
{% trans 'Deactive selected' %}
</option>
<option>
{% trans 'Export selected' %}
</option>
</select>
<div
class=
"input-group-btn pull-left"
style=
"padding-left: 5px;"
>
<button
id=
'search_btn'
type=
"submit"
style=
"height: 32px;"
class=
"btn btn-sm btn-primary"
>
{% trans 'Submit' %}
</button>
<div
class=
"row"
>
<div
class=
"col-sm-4"
>
{# Update batch #}
{% block content_bottom_left %}
<form
id=
""
method=
"get"
action=
""
class=
" mail-search"
>
<div
class=
"input-group"
>
<select
class=
"form-control m-b"
style=
"width: auto"
>
<option>
{% trans 'Delete selected' %}
</option>
<option>
{% trans 'Update selected' %}
</option>
<option>
{% trans 'Deactive selected' %}
</option>
<option>
{% trans 'Export selected' %}
</option>
</select>
<div
class=
"input-group-btn pull-left"
style=
"padding-left: 5px;"
>
<button
id=
'search_btn'
type=
"submit"
style=
"height: 32px;"
class=
"btn btn-sm btn-primary"
>
{% trans 'Submit' %}
</button>
</div>
</div>
</form>
{% endblock %}
</div>
{% block table_pagination %}
{% include '_pagination.html' %}
{% endblock %}
</div>
</div>
</div>
</div>
</form>
{% for tag in tag_list %}
<a
href=
"{% url 'assets:asset-tags' tag_id=tag.0%}"
>
{{ tag.1}}({{ tag.2 }})
</a>
{% endfor %}
</div>
</div>
{% endblock %}
{% block custom_foot_js %}
<script
type=
"text/javascript"
>
window
.
onload
=
function
(){
var
tag_on
=
document
.
getElementsByName
(
"
tag_on
"
);
var
oDiv
=
document
.
getElementById
(
"
ydxbd
"
);
if
(
tag_on
.
length
>
0
){
oDiv
.
style
.
display
=
"
block
"
;
}
};
function
tagShow
()
{
var
oDiv
=
document
.
getElementById
(
"
ydxbd
"
);
if
(
oDiv
.
style
.
display
==
'
none
'
){
oDiv
.
style
.
display
=
"
block
"
;
}
else
{
oDiv
.
style
.
display
=
"
none
"
;
}
};
$
(
document
).
ready
(
function
(){
var
table
=
$
(
'
#editable
'
).
DataTable
({
aLengthMenu
:
[[
2
,
25
,
50
,
-
1
],
[
"
2
"
,
"
25
"
,
"
50
"
,
"
all
"
]],
"
aaSorting
"
:
[[
7
,
"
asc
"
]],
"
aoColumnDefs
"
:
[
{
"
bSortable
"
:
false
,
"
aTargets
"
:
[
0
]
}],
"
bAutoWidth
"
:
false
,
"
language
"
:
{
"
url
"
:
"
/static/js/plugins/dataTables/i18n/zh-hans.json
"
},
columns
:
[
{
data
:
"
checkbox
"
},
{
data
:
"
id
"
},
{
data
:
"
name
"
},
{
data
:
"
ip
"
},
{
data
:
"
type
"
},
{
data
:
"
group
"
},
{
data
:
"
dp
"
},
{
data
:
"
op
"
}
]
});
//将ID列隐藏
//table.column('1').visible(false);
$
(
'
#editable tbody
'
).
on
(
'
click
'
,
'
tr
'
,
function
()
{
//alert($(this).hasClass('selected'));
if
(
$
(
this
).
hasClass
(
'
selected
'
)){
$
(
this
).
removeClass
(
'
selected
'
);
this
.
children
[
0
].
children
[
0
].
checked
=
0
;
}
else
{
$
(
this
).
addClass
(
'
selected
'
);
this
.
children
[
0
].
children
[
0
].
checked
=
1
;
};
});
$
(
'
#close-btn
'
).
on
(
'
click
'
,
function
(){
$
(
'
#modal
'
).
modal
(
'
hide
'
);
});
$
(
'
#save-btn
'
).
on
(
'
click
'
,
function
(){
// alert( table.rows('.selected').data().length +' row(s) selected' );
var
d
=
table
.
rows
(
'
.selected
'
).
data
();
var
size
=
d
.
length
;
document
.
getElementById
(
'
add_asset
'
).
value
=
size
;
var
column2
=
table
.
rows
(
'
.selected
'
).
data
();
$
(
"
#asset_sed
"
).
find
(
"
input[name='assets']
"
).
remove
();
for
(
var
i
=
0
;
i
<
column2
.
length
;
i
++
){
column2
[
i
].
checkbox
=
'
<input name="checked" value="1" checked="" type="checkbox">
'
;
var
value
=
column2
[
i
].
id
;
$
(
"
#asset_sed
"
).
append
(
"
<input type='hidden' name='assets' value='
"
+
value
+
"
'>
"
);
}
$
(
'
#modal
'
).
modal
(
'
hide
'
);
});
});
//$(document).ready
var
bCheck
=
1
;
function
checkAll
(){
if
(
bCheck
){
$
(
"
tr[name='oAssets']
"
).
each
(
function
(){
oCheckbox
=
this
.
children
[
0
].
children
[
0
];
$
(
this
).
toggleClass
(
'
selected
'
,
true
);
oCheckbox
.
checked
=
1
;
});
document
.
getElementById
(
'
check_all
'
).
checked
=
1
;
bCheck
=
0
;
}
else
{
$
(
"
tr[name='oAssets']
"
).
each
(
function
(){
oCheckbox
=
this
.
children
[
0
].
children
[
0
];
$
(
this
).
toggleClass
(
'
selected
'
,
false
);
oCheckbox
.
checked
=
0
;
});
document
.
getElementById
(
'
check_all
'
).
checked
=
0
;
bCheck
=
1
;
};
};
</script>
{% endblock %}
apps/assets/templates/assets/asset_tag_create.html
0 → 100644
浏览文件 @
73f5891f
{% extends 'base.html' %}
{% load i18n %}
{% load static %}
{% load bootstrap %}
{% block custom_head_css_js %}
<link
href=
"{% static 'css/plugins/select2/select2.min.css' %}"
rel=
"stylesheet"
>
<script
src=
"{% static 'js/plugins/select2/select2.full.min.js' %}"
></script>
<style>
div
.dataTables_wrapper
div
.dataTables_filter
,
.dataTables_length
{
float
:
left
;
}
</style>
{% endblock %}
{% block content %}
<div
class=
"wrapper wrapper-content animated fadeInRight"
>
<div
class=
"row"
>
<div
class=
"col-sm-10"
>
<div
class=
"ibox float-e-margins"
>
<div
id=
"ibox-content"
class=
"ibox-title"
>
<h5>
{{ action }}
</h5>
<div
class=
"ibox-tools"
>
<a
class=
"collapse-link"
>
<i
class=
"fa fa-chevron-up"
></i>
</a>
<a
class=
"dropdown-toggle"
data-toggle=
"dropdown"
href=
"#"
>
<i
class=
"fa fa-wrench"
></i>
</a>
<a
class=
"close-link"
>
<i
class=
"fa fa-times"
></i>
</a>
</div>
</div>
<div
class=
"ibox-content"
>
<div
class=
"panel blank-panel"
>
<div
class=
"panel-body"
>
<div
class=
"tab-content"
>
<div
id=
"tab-1"
class=
"ibox float-e-margins tab-pane active"
></div>
<form
id=
"tagForm"
method=
"post"
class=
"form-horizontal"
>
{% csrf_token %}
<h3
class=
"widget-head-color-box"
>
基本信息
</h3>
{{ form.name|bootstrap_horizontal }}
<div
class=
"form-group"
>
<label
class=
"col-sm-2 control-label"
>
关联的资产
</label>
<div
class=
"col-sm-9"
id=
"asset_sed"
>
<input
type=
"text"
class=
" form-control"
id=
"add_asset"
value=
"{{ assets_count }}"
>
</div>
</div>
<div
class=
"form-group"
>
<div
class=
"col-sm-4 col-sm-offset-5"
>
<button
class=
"btn btn-white"
type=
"reset"
>
重置
</button>
<button
class=
"btn btn-primary"
type=
"submit"
>
提交
</button>
<div
id=
'box2'
>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- 模态框(Modal) -->
<div
class=
"modal fade"
id=
"modal"
tabindex=
"-1"
role=
"dialog"
aria-labelledby=
"myModalLabel"
aria-hidden=
"true"
>
<div
class=
"modal-dialog modal-lg"
>
<div
class=
"modal-content"
id=
"box"
>
<!--此部分为主体内容,将远程加载进来-->
</div>
</div>
</div>
{% endblock %}
{% block custom_foot_js %}
<script
type=
"text/javascript"
>
$
(
document
).
ready
(
function
()
{
$
(
'
.select2
'
).
select2
();
$
(
'
.select2-system-user
'
).
select2
();
})
$
(
'
#add_asset
'
).
on
(
'
click
'
,
function
(){
$
(
'
#modal
'
).
modal
(
'
show
'
);
});
$
(
'
#modal
'
).
modal
({
show
:
false
,
backdrop
:
'
static
'
,
keyboard
:
'
false
'
,
remote
:
"
{% url 'assets:asset-modal-list' %}?tag_id={{ tag_id }}
"
,
});
$
(
'
#modal
'
).
on
(
'
show.bs.modal
'
,
function
(){
//alert('当调用show方法时,立即触发;')
});
$
(
'
#modal
'
).
on
(
'
shown.bs.modal
'
,
function
(){
//alert('当弹窗完全加载完后,再触发;')
});
$
(
'
#modal
'
).
on
(
'
hide.bs.modal
'
,
function
(){
//alert('当关闭时,立即触发;')
});
$
(
'
#modal
'
).
on
(
'
hidden.bs.modal
'
,
function
(){
//alert('当关完全关闭后,再触发;')
});
$
(
'
#modal
'
).
on
(
'
loaded.bs.modal
'
,
function
(){
//alert('当远程数据加载完毕后,再触发;')
});
</script>
{% endblock %}
\ No newline at end of file
apps/assets/templates/assets/asset_tag_detail.html
0 → 100644
浏览文件 @
73f5891f
{% extends 'base.html' %}
{% load common_tags %}
{% load users_tags %}
{% load static %}
{% load i18n %}
{% block custom_head_css_js %}
<link
href=
"{% static "
css
/
plugins
/
select2
/
select2.min.css
"
%}"
rel=
"stylesheet"
>
<script
src=
"{% static "
js
/
plugins
/
select2
/
select2.full.min.js
"
%}"
></script>
{% endblock %}
{% block content %}
<div
class=
"wrapper wrapper-content animated fadeInRight"
>
<div
class=
"row"
>
<div
class=
"col-sm-12"
>
<div
class=
"ibox float-e-margins"
>
<div
class=
"panel-options"
>
<ul
class=
"nav nav-tabs"
>
<li
class=
"active"
><a
href=
""
class=
"text-center"
><i
class=
"fa fa-laptop"
></i>
{% trans 'Detail' %}
</a>
</li>
</ul>
</div>
<div
class=
"tab-content"
>
<div
class=
"col-sm-7"
style=
"padding-left: 0;"
>
<div
class=
"ibox float-e-margins"
>
<div
class=
"ibox-title"
>
<span
class=
"label"
><b>
{{ asset_tag.name }}
</b></span>
<div
class=
"ibox-tools"
>
<a
class=
"collapse-link"
>
<i
class=
"fa fa-chevron-up"
></i>
</a>
<a
class=
"dropdown-toggle"
data-toggle=
"dropdown"
href=
"#"
>
<i
class=
"fa fa-wrench"
></i>
</a>
<ul
class=
"dropdown-menu dropdown-user"
>
</ul>
<a
class=
"close-link"
>
<i
class=
"fa fa-times"
></i>
</a>
</div>
</div>
<div
class=
"ibox-content"
>
<table
class=
"table"
>
<tbody>
<tr
class=
"no-borders-tr"
>
<td>
{% trans 'Tag Name' %}:
</td>
<td><b>
{{ asset_tag.name }}
</b></td>
</tr>
<tr>
<td>
{% trans 'Created by' %}:
</td>
<td><b>
{{ asset_tag.created_by }}
</b></td>
</tr>
<tr>
<td>
{% trans 'Date created' %}:
</td>
<td><b>
{{ asset_tag.created_time|date:"Y-m-d H:i:s" }}
</b></td>
</tr>
</tbody>
</table>
</div>
</div>
<div
class=
"ibox float-e-margins"
>
<div
class=
"ibox-title"
>
<span
style=
"float: left"
></span>
{% trans 'Asset list of ' %}
<b>
{{ asset_tag.name }}
</b></span>
<div
class=
"ibox-tools"
>
<a
class=
"collapse-link"
>
<i
class=
"fa fa-chevron-up"
></i>
</a>
<a
class=
"dropdown-toggle"
data-toggle=
"dropdown"
href=
"#"
>
<i
class=
"fa fa-wrench"
></i>
</a>
<ul
class=
"dropdown-menu dropdown-user"
>
</ul>
<a
class=
"close-link"
>
<i
class=
"fa fa-times"
></i>
</a>
</div>
</div>
<div
class=
"ibox-content"
>
<table
class=
"table table-hover"
>
<thead>
<tr>
<th>
{% trans 'Hostname' %}
</th>
<th>
{% trans 'IP' %}
</th>
<th>
{% trans 'Port' %}
</th>
<th>
{% trans 'Alive' %}
</th>
</tr>
</thead>
<tbody>
{% for asset in page_obj %}
<tr>
<td>
{{ asset.hostname }}
</td>
<td>
{{ asset.ip }}
</td>
<td>
{{ asset.port }}
</td>
<td>
Alive
</td>
</tr>
{% endfor %}
</tbody>
</table>
<div
class=
"row"
>
{% include '_pagination.html' %}
</div>
</div>
</div>
</div>
<div
class=
"col-sm-5"
style=
"padding-left: 0;padding-right: 0"
>
<div
class=
"panel panel-primary"
>
<div
class=
"panel-heading"
>
<i
class=
"fa fa-info-circle"
></i>
{% trans 'Associate system user' %}
</div>
<div
class=
"panel-body"
>
<table
class=
"table"
>
<tbody>
<tr
class=
"no-borders-tr"
>
<td
width=
"50%"
>
{% trans 'repush system user' %}:
</td>
<td>
<span
style=
"float: right"
>
<button
class=
"btn btn-danger btn-xs"
type=
"button"
><i
class=
"fa fa-refresh"
></i></button>
</span>
</td>
</tr>
<form>
<tr
class=
"no-borders-tr"
>
<td
colspan=
"2"
>
<select
data-placeholder=
"{% trans 'Select system user' %}"
class=
"select2"
style=
"width: 100%"
multiple=
""
tabindex=
"4"
>
{% for group in groups %}
<option
value=
"{{ group.id }}"
>
{{ group.name }}
</option>
{% endfor %}
</select>
</td>
</tr>
<tr
class=
"no-borders-tr"
>
<td
colspan=
"2"
>
<button
type=
"button"
class=
"btn btn-primary btn-sm"
>
{% trans 'Associate' %}
</button>
</td>
</tr>
</form>
{% for group in user.groups.all %}
<tr>
<td
><b>
{{ group.name }}
</b></td>
<td>
<button
class=
"btn btn-danger btn-xs"
type=
"button"
style=
"float: right;"
><i
class=
"fa fa-minus"
></i></button>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
<div
class=
"panel panel-info"
>
<div
class=
"panel-heading"
>
<i
class=
"fa fa-info-circle"
></i>
{% trans 'Add asset to this group' %}
</div>
<div
class=
"panel-body"
>
<table
class=
"table"
>
<tbody>
<form>
<tr
class=
"no-borders-tr"
>
<td
colspan=
"2"
>
<select
data-placeholder=
"{% trans 'Select asset user' %}"
class=
"select2"
style=
"width: 100%"
multiple=
""
tabindex=
"4"
>
{% for group in groups %}
<option
value=
"{{ group.id }}"
>
{{ group.name }}
</option>
{% endfor %}
</select>
</td>
</tr>
<tr
class=
"no-borders-tr"
>
<td
colspan=
"2"
>
<button
type=
"button"
class=
"btn btn-info btn-sm"
>
{% trans 'Add' %}
</button>
</td>
</tr>
</form>
{% for group in user.groups.all %}
<tr>
<td
><b>
{{ group.name }}
</b></td>
<td>
<button
class=
"btn btn-danger btn-xs"
type=
"button"
style=
"float: right;"
><i
class=
"fa fa-minus"
></i></button>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
{% block custom_foot_js %}
<script>
{
#
function
switch_user_status
(
obj
)
{
#
}
{
#
var
status
=
$
(
obj
).
prop
(
'
checked
'
);
#
}
{
##
}
{
#
$
.
ajax
({
#
}
{
#
url
:
"
{% url 'users:user-active-api' pk=user.id %}
"
,
#
}
{
#
type
:
"
PUT
"
,
#
}
{
#
data
:
{
#
}
{
#
'
is_active
'
:
status
#
}
{
#
},
#
}
{
#
success
:
function
(
data
,
status
)
{
#
}
{
#
console
.
log
(
data
)
#
}
{
#
},
#
}
{
#
error
:
function
()
{
#
}
{
#
console
.
log
(
'
error
'
)
#
}
{
#
}
#
}
{
#
})
#
}
{
#
}
#
}
$
(
document
).
ready
(
function
()
{
$
(
'
.select2
'
).
select2
();
})
</script>
{% endblock %}
\ No newline at end of file
apps/assets/templates/assets/asset_tags_list.html
0 → 100644
浏览文件 @
73f5891f
{% extends '_base_list.html' %}
{% load i18n %}
{% load common_tags %}
{% block content_left_head %}
<a
href=
"{% url 'assets:asset-tag-create' %}"
class=
"btn btn-sm btn-primary "
>
{% trans "Create tag" %}
</a>
{% endblock %}
{% block table_head %}
<th
class=
"text-center"
>
<input
type=
"checkbox"
id=
"check_all"
onclick=
"checkAll('check_all', 'checked')"
>
</th>
<th
class=
"text-center"
><a
href=
"{% url 'assets:asset-tag-list' %}?sort=name"
>
{% trans 'Tag Name' %}
</a></th>
<th
class=
"text-center"
>
{% trans 'Asset num' %}
</th>
<th
class=
"text-center"
></th>
{% endblock %}
{% block table_body %}
{% for asset_tag in asset_tags_list %}
<tr
class=
"gradeX"
>
<td
class=
"text-center"
>
<input
type=
"checkbox"
name=
"checked"
value=
"{{ asset_tag.id }}"
>
</td>
<td
class=
"text-center"
>
<a
href=
"{% url 'assets:asset-tag-detail' pk=asset_tag.id %}"
>
{{ asset_tag.name }}
</a>
</td>
<td
class=
"text-center"
>
{{ asset_tag.asset_set.count }}
</td>
<td
class=
"text-center"
>
<a
href=
"{% url 'assets:asset-tag-update' pk=asset_tag.id %}"
class=
"btn btn-xs btn-info"
>
{% trans 'Update' %}
</a>
<a
onclick=
"objectDelete(this,'{{ asset_tag.name }}','{% url 'assets:asset-tag-delete' asset_tag.id %}')"
class=
"btn btn-xs btn-danger del"
>
{% trans 'Delete' %}
</a>
</td>
</tr>
{% endfor %}
{% endblock %}
{% block content_bottom_left %}
<form
id=
""
method=
"get"
action=
""
class=
" mail-search"
>
<div
class=
"input-group"
>
<select
class=
"form-control m-b"
style=
"width: auto"
>
<option>
{% trans 'Delete selected' %}
</option>
<option>
{% trans 'Update selected' %}
</option>
<option>
{% trans 'Deactive selected' %}
</option>
<option>
{% trans 'Export selected' %}
</option>
</select>
<div
class=
"input-group-btn pull-left"
style=
"padding-left: 5px;"
>
<button
id=
'search_btn'
type=
"submit"
style=
"height: 32px;"
class=
"btn btn-sm btn-primary"
>
{% trans 'Submit' %}
</button>
</div>
</div>
</form>
{% endblock %}
apps/assets/templatetags/asset_tags.py
0 → 100644
浏览文件 @
73f5891f
from
django
import
template
from
django.utils
import
timezone
from
django.conf
import
settings
register
=
template
.
Library
()
apps/assets/templatetags/example_tags.py
已删除
100644 → 0
浏览文件 @
b99b88a3
apps/assets/utils.py
浏览文件 @
73f5891f
# ~*~ coding: utf-8 ~*~
#
from
rest_framework
import
serializers
from
models
import
Asset
from
models
import
Tag
from
django.views.generic.edit
import
CreateView
class
CreateAssetTagsMiXin
(
CreateView
):
def
get_form_kwargs
(
self
):
tags_list
=
self
.
request
.
POST
.
getlist
(
'tags'
)
kwargs
=
{
'initial'
:
self
.
get_initial
(),
'prefix'
:
self
.
get_prefix
(),
}
if
self
.
request
.
method
in
(
'POST'
,
'PUT'
):
post_data
=
self
.
request
.
POST
.
copy
()
if
post_data
.
has_key
(
'tags'
):
post_data
.
pop
(
'tags'
)
for
t
in
tags_list
:
try
:
oTag
=
Tag
.
objects
.
get
(
pk
=
int
(
t
))
except
(
Tag
.
DoesNotExist
,
UnicodeEncodeError
):
oTag
=
Tag
(
name
=
t
,
created_by
=
self
.
request
.
user
.
username
or
'Admin'
)
oTag
.
save
()
post_data
.
update
({
'tags'
:
oTag
.
pk
})
else
:
post_data
.
update
({
'tags'
:
int
(
t
)})
kwargs
.
update
({
'data'
:
post_data
,
'files'
:
self
.
request
.
FILES
,
})
return
kwargs
class
UpdateAssetTagsMiXin
(
CreateAssetTagsMiXin
):
def
get_form_kwargs
(
self
):
kwargs
=
super
(
UpdateAssetTagsMiXin
,
self
).
get_form_kwargs
()
if
hasattr
(
self
,
'object'
):
kwargs
.
update
({
'instance'
:
self
.
object
})
return
kwargs
\ No newline at end of file
apps/assets/views.py
浏览文件 @
73f5891f
...
...
@@ -12,6 +12,7 @@ from django.views.generic.detail import DetailView, SingleObjectMixin
from
django.shortcuts
import
get_object_or_404
,
reverse
,
redirect
from
common.utils
import
int_seq
from
.utils
import
CreateAssetTagsMiXin
,
UpdateAssetTagsMiXin
from
.models
import
Asset
,
AssetGroup
,
IDC
,
AssetExtend
,
AdminUser
,
SystemUser
,
Tag
from
.forms
import
*
from
.hands
import
AdminUserRequiredMixin
...
...
@@ -37,7 +38,7 @@ class AssetListView(AdminUserRequiredMixin, ListView):
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
'app'
:
'Assets'
,
'action'
:
'
A
sset list'
,
'action'
:
'
a
sset list'
,
'tag_list'
:
[(
i
.
id
,
i
.
name
,
i
.
asset_set
.
all
().
count
())
for
i
in
Tag
.
objects
.
all
().
order_by
(
'name'
)]
}
...
...
@@ -45,24 +46,23 @@ class AssetListView(AdminUserRequiredMixin, ListView):
return
super
(
AssetListView
,
self
).
get_context_data
(
**
kwargs
)
class
AssetCreateView
(
AdminUserRequiredMixin
,
CreateView
):
class
AssetCreateView
(
AdminUserRequiredMixin
,
CreateAssetTagsMiXin
,
CreateView
):
model
=
Asset
tag_type
=
'asset'
form_class
=
AssetCreateForm
template_name
=
'assets/asset_create.html'
success_url
=
reverse_lazy
(
'assets:asset-list'
)
def
form_invalid
(
self
,
form
):
def
form_valid
(
self
,
form
):
asset
=
form
.
save
()
asset
.
created_by
=
self
.
request
.
user
.
username
or
'Admin'
asset
.
save
()
return
super
(
AssetCreateView
,
self
).
form_valid
(
form
)
#tags = form.cleaned_data['tags']
def
form_invalid
(
self
,
form
):
print
(
form
.
errors
)
return
super
(
AssetCreateView
,
self
).
form_invalid
(
form
)
def
form_valid
(
self
,
form
):
tag_name_list
=
form
.
cleaned_data
[
'tags'
]
# print self.tag_type,tag_name_list
return
super
(
AssetCreateView
,
self
).
form_valid
(
form
)
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
...
...
@@ -74,7 +74,9 @@ class AssetCreateView(AdminUserRequiredMixin, CreateView):
return
super
(
AssetCreateView
,
self
).
get_context_data
(
**
kwargs
)
class
AssetUpdateView
(
AdminUserRequiredMixin
,
UpdateView
):
class
AssetUpdateView
(
AdminUserRequiredMixin
,
UpdateAssetTagsMiXin
,
UpdateView
):
model
=
Asset
form_class
=
AssetCreateForm
template_name
=
'assets/asset_update.html'
...
...
@@ -90,7 +92,6 @@ class AssetUpdateView(AdminUserRequiredMixin, UpdateView):
def
form_invalid
(
self
,
form
):
print
(
form
.
errors
)
print
"jsf"
return
super
(
AssetUpdateView
,
self
).
form_invalid
(
form
)
...
...
@@ -581,7 +582,10 @@ class TagView(ListView):
return
asset_list
def
get_context_data
(
self
,
**
kwargs
):
kwargs
[
'app'
]
=
'Assets'
kwargs
[
'action'
]
=
'asset list'
kwargs
[
'tag_list'
]
=
[(
i
.
id
,
i
.
name
,
i
.
asset_set
.
all
().
count
()
)
for
i
in
Tag
.
objects
.
all
().
order_by
(
'name'
)]
kwargs
[
'tag_id'
]
=
self
.
kwargs
[
'tag_id'
]
return
super
(
TagView
,
self
).
get_context_data
(
**
kwargs
)
...
...
apps/common/templatetags/common_tags.py
浏览文件 @
73f5891f
...
...
@@ -43,3 +43,7 @@ def join_attr(seq, attr=None, sep=None):
seq
=
[
getattr
(
obj
,
attr
)
for
obj
in
seq
]
print
(
seq
)
return
sep
.
join
(
seq
)
@
register
.
filter
def
IntToStr
(
value
):
return
str
(
value
)
\ No newline at end of file
apps/static/css/jumpserver.css
浏览文件 @
73f5891f
...
...
@@ -196,3 +196,22 @@ table.dataTable tbody td.selected td i.text-navy
.m-r-30
{
margin-right
:
30px
!important
;
}
.ydxbd
{
font-size
:
12px
;
width
:
100%
;
overflow
:
hidden
;
padding-top
:
15px
;
margin-bottom
:
15px
;
display
:
block
;
background
:
#f4f4f4
;
padding-left
:
10px
;
}
.mar
{
margin-left
:
2px
;
line-height
:
15px
;
}
.mar-j
{
margin-left
:
3px
;
margin-right
:
3px
;
}
\ No newline at end of file
apps/static/css/plugins/inputTags.css
浏览文件 @
73f5891f
@import
url("https://fonts.
useso
.com/css?family=Open+Sans:300,400,600,700")
;
@import
url("https://fonts.
useso
.com/css?family=Roboto:400,300,500,700")
;
@import
url("https://fonts.
googleapis
.com/css?family=Open+Sans:300,400,600,700")
;
@import
url("https://fonts.
googleapis
.com/css?family=Roboto:400,300,500,700")
;
/** {*/
/*box-sizing: border-box;*/
/*}*/
...
...
apps/templates/_base_list.html
浏览文件 @
73f5891f
...
...
@@ -14,9 +14,11 @@
<div
class=
"col-sm-12"
>
<div
class=
"ibox float-e-margins"
>
<div
class=
"ibox-title"
>
<h5>
{{ action }}
</h5>
<h5>
{{ action }}
</h5>
<div
class=
"ibox-tools"
>
<a
class=
"collap
i
se-link"
>
<a
class=
"collapse-link"
>
<i
class=
"fa fa-chevron-up"
></i>
</a>
<a
class=
"dropdown-toggle"
data-toggle=
"dropdown"
href=
"#"
>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录