Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
gjl2004yn
jumpserver
提交
b99b88a3
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,发现更多精彩内容 >>
提交
b99b88a3
编写于
10月 08, 2016
作者:
江
江世峰
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
asset:update tag
上级
0c611b64
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
166 addition
and
23 deletion
+166
-23
apps/assets/forms.py
apps/assets/forms.py
+36
-1
apps/assets/models.py
apps/assets/models.py
+1
-1
apps/assets/templates/assets/asset_create.html
apps/assets/templates/assets/asset_create.html
+0
-2
apps/assets/templates/assets/asset_group_create.html
apps/assets/templates/assets/asset_group_create.html
+1
-1
apps/assets/templates/assets/asset_list.html
apps/assets/templates/assets/asset_list.html
+2
-3
apps/assets/templates/assets/asset_modal_list.html
apps/assets/templates/assets/asset_modal_list.html
+5
-3
apps/assets/templates/assets/asset_update.html
apps/assets/templates/assets/asset_update.html
+4
-6
apps/assets/urls.py
apps/assets/urls.py
+7
-1
apps/assets/views.py
apps/assets/views.py
+109
-4
apps/templates/_nav.html
apps/templates/_nav.html
+1
-1
未找到文件。
apps/assets/forms.py
浏览文件 @
b99b88a3
...
...
@@ -40,6 +40,7 @@ class AssetCreateForm(forms.ModelForm):
self
.
instance
.
tags
.
clear
()
self
.
instance
.
tags
.
add
(
*
tuple
(
tags
))
class
Meta
:
model
=
Asset
...
...
@@ -53,7 +54,8 @@ class AssetCreateForm(forms.ModelForm):
'groups'
:
forms
.
SelectMultiple
(
attrs
=
{
'class'
:
'select2'
,
'data-placeholder'
:
_
(
'Select asset groups'
)}),
'tags'
:
forms
.
SelectMultiple
(
attrs
=
{
'class'
:
'select2'
,
'data-placeholder'
:
_
(
'Select asset groups'
)}),
'id'
:
'tags'
,
'data-placeholder'
:
_
(
'Select asset tags'
)}),
'system_users'
:
forms
.
SelectMultiple
(
attrs
=
{
'class'
:
'select2'
,
'data-placeholder'
:
_
(
'Select asset system users'
)}),
'admin_user'
:
forms
.
Select
(
attrs
=
{
'class'
:
'select2'
,
'data-placeholder'
:
_
(
'Select asset admin user'
)}),
...
...
@@ -263,4 +265,37 @@ class SystemUserForm(forms.ModelForm):
'username'
:
'* required'
,
'auth_push'
:
'Auto push system user to asset'
,
'auth_update'
:
'Auto update system user ssh key'
,
}
class
AssetTagForm
(
forms
.
ModelForm
):
assets
=
forms
.
ModelMultipleChoiceField
(
queryset
=
Asset
.
objects
.
all
(),
label
=
_
(
'Asset'
),
required
=
False
,
widget
=
forms
.
SelectMultiple
(
attrs
=
{
'class'
:
'select2'
,
'data-placeholder'
:
_
(
'Select assets'
)})
)
def
__init__
(
self
,
*
args
,
**
kwargs
):
if
kwargs
.
get
(
'instance'
,
None
):
initial
=
kwargs
.
get
(
'initial'
,
{})
initial
[
'assets'
]
=
kwargs
[
'instance'
].
asset_set
.
all
()
super
(
AssetTagForm
,
self
).
__init__
(
*
args
,
**
kwargs
)
def
_save_m2m
(
self
):
super
(
AssetTagForm
,
self
).
_save_m2m
()
assets
=
self
.
cleaned_data
[
'assets'
]
self
.
instance
.
asset_set
.
clear
()
self
.
instance
.
asset_set
.
add
(
*
tuple
(
assets
))
class
Meta
:
model
=
Tag
fields
=
[
"name"
,
]
widgets
=
{
'name'
:
forms
.
TextInput
(
attrs
=
{}),
}
help_texts
=
{
'name'
:
'* required'
,
}
\ No newline at end of file
apps/assets/models.py
浏览文件 @
b99b88a3
...
...
@@ -365,7 +365,7 @@ class Asset(models.Model):
class
Tag
(
models
.
Model
):
name
=
models
.
CharField
(
'标签名'
,
max_length
=
64
)
name
=
models
.
CharField
(
'标签名'
,
max_length
=
64
,
unique
=
True
)
created_time
=
models
.
DateTimeField
(
'创建时间'
,
auto_now_add
=
True
)
created_by
=
models
.
CharField
(
max_length
=
32
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Created by'
))
...
...
apps/assets/templates/assets/asset_create.html
浏览文件 @
b99b88a3
...
...
@@ -25,8 +25,6 @@
<div
class=
"hr-line-dashed"
></div>
<h3>
{% trans 'Other' %}
</h3>
{{ form.tags|bootstrap_horizontal }}
{{ form.comment|bootstrap_horizontal }}
<div
class=
"hr-line-dashed"
></div>
...
...
apps/assets/templates/assets/asset_group_create.html
浏览文件 @
b99b88a3
...
...
@@ -37,7 +37,7 @@ div.dataTables_wrapper div.dataTables_filter,
<div
class=
"panel-body"
>
<div
class=
"tab-content"
>
<div
id=
"tab-1"
class=
"ibox float-e-margins tab-pane active"
></div>
<form
id=
"
IDC
Form"
method=
"post"
class=
"form-horizontal"
>
<form
id=
"
group
Form"
method=
"post"
class=
"form-horizontal"
>
{% csrf_token %}
<h3
class=
"widget-head-color-box"
>
资产组信息
</h3>
{{ form.name|bootstrap_horizontal }}
...
...
apps/assets/templates/assets/asset_list.html
浏览文件 @
b99b88a3
...
...
@@ -42,8 +42,7 @@
</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>
-
{#
<a
href=
"{% url '' %}"
>
{% trans 'Delete' %}
</a>
#}
<a
href=
"{% url 'assets:asset-delete' pk=asset.id %}"
class=
"btn btn-xs btn-danger del"
>
{% trans 'Delete' %}
</a>
</td>
</tr>
{% endfor %}
...
...
@@ -72,7 +71,7 @@
<a
href=
"{% url 'assets:asset-tags' tag_id=tag.0%}"
>
{{ tag.1}}({{ tag.2 }})
</a>
{% endfor %}
{% endfor %}
{% endblock %}
...
...
apps/assets/templates/assets/asset_modal_list.html
浏览文件 @
b99b88a3
...
...
@@ -21,7 +21,7 @@
</thead>
<tbody>
{% for asset in asset_modal_list %}
{% if asset.id in
group
_assets %}
{% if asset.id in
all
_assets %}
<tr
name=
"oAssets"
class=
"odd selected"
>
<td
class=
"text-center"
><input
type=
"checkbox"
name=
"checked"
value=
"{{ asset.id }}"
checked=
"checked"
></td>
{% else %}
...
...
@@ -47,7 +47,6 @@
<script
type=
"text/javascript"
>
//$(window).load(function (){
$
(
document
).
ready
(
function
(){
var
table
=
$
(
'
#editable
'
).
DataTable
({
...
...
@@ -68,7 +67,7 @@ $(document).ready(function(){
{
data
:
"
dp
"
}
]
});
//
讲
ID列隐藏
//
将
ID列隐藏
table
.
column
(
'
1
'
).
visible
(
false
);
$
(
'
#editable tbody
'
).
on
(
'
click
'
,
'
tr
'
,
function
()
{
...
...
@@ -82,6 +81,9 @@ $(document).ready(function(){
};
});
$
(
'
#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
();
...
...
apps/assets/templates/assets/asset_update.html
浏览文件 @
b99b88a3
...
...
@@ -70,12 +70,10 @@
<script>
$
(
document
).
ready
(
function
()
{
$
(
'
.select2
'
).
select2
();
{
#
$
(
'
#tags
'
).
inputTags
({
#
}
{
#
tags
:
[{
%
for
tag
in
form
.
tags
.
value
%
}
{{
tag
|
safe
}},
{
%
endfor
%
}]
#
}
{
#
});
#
}
$
(
'
#tags
'
).
inputTags
(
);
$
(
"
#tags
"
).
select2
({
tags
:
true
,
maximumSelectionLength
:
8
//最多能够选择的个数
});
})
</script>
{% endblock %}
\ No newline at end of file
apps/assets/urls.py
浏览文件 @
b99b88a3
...
...
@@ -28,7 +28,13 @@ urlpatterns = [
url
(
r
'^asset-group/(?P<pk>[0-9]+)$'
,
views
.
AssetGroupDetailView
.
as_view
(),
name
=
'asset-group-detail'
),
url
(
r
'^asset-group/(?P<pk>[0-9]+)/update$'
,
views
.
AssetGroupUpdateView
.
as_view
(),
name
=
'asset-group-update'
),
url
(
r
'^asset-group/(?P<pk>[0-9]+)/delete$'
,
views
.
AssetGroupDeleteView
.
as_view
(),
name
=
'asset-group-delete'
),
url
(
r
'^asset-tag/(?P<tag_id>[0-9]+)$'
,
views
.
TagView
.
as_view
(),
name
=
'asset-tags'
),
url
(
r
'^tags$'
,
views
.
TagsListView
.
as_view
(),
name
=
'asset-tag-list'
),
url
(
r
'^asset-by-tag/(?P<tag_id>[0-9]+)$'
,
views
.
TagView
.
as_view
(),
name
=
'asset-tags'
),
url
(
r
'^tags/create$'
,
views
.
AssetTagCreateView
.
as_view
(),
name
=
'asset-tag-create'
),
url
(
r
'^asset-tag/(?P<pk>[0-9]+)$'
,
views
.
AssetTagDetailView
.
as_view
(),
name
=
'asset-tag-detail'
),
url
(
r
'^asset-tag/(?P<pk>[0-9]+)/update$'
,
views
.
AssetTagUpdateView
.
as_view
(),
name
=
'asset-tag-update'
),
url
(
r
'^asset-tag/(?P<pk>[0-9]+)/delete$'
,
views
.
AssetTagDeleteView
.
as_view
(),
name
=
'asset-tag-delete'
),
# Resource idc url
url
(
r
'^idc$'
,
views
.
IDCListView
.
as_view
(),
name
=
'idc-list'
),
...
...
apps/assets/views.py
浏览文件 @
b99b88a3
...
...
@@ -13,7 +13,7 @@ from django.shortcuts import get_object_or_404, reverse, redirect
from
common.utils
import
int_seq
from
.models
import
Asset
,
AssetGroup
,
IDC
,
AssetExtend
,
AdminUser
,
SystemUser
,
Tag
from
.forms
import
AssetCreateForm
,
AssetGroupForm
,
IDCForm
,
AdminUserForm
,
SystemUserForm
from
.forms
import
*
from
.hands
import
AdminUserRequiredMixin
...
...
@@ -53,12 +53,14 @@ class AssetCreateView(AdminUserRequiredMixin, CreateView):
success_url
=
reverse_lazy
(
'assets:asset-list'
)
def
form_invalid
(
self
,
form
):
#tags = form.cleaned_data['tags']
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
#
print self.tag_type,tag_name_list
return
super
(
AssetCreateView
,
self
).
form_valid
(
form
)
...
...
@@ -86,6 +88,11 @@ class AssetUpdateView(AdminUserRequiredMixin, UpdateView):
kwargs
.
update
(
context
)
return
super
(
AssetUpdateView
,
self
).
get_context_data
(
**
kwargs
)
def
form_invalid
(
self
,
form
):
print
(
form
.
errors
)
print
"jsf"
return
super
(
AssetUpdateView
,
self
).
form_invalid
(
form
)
class
AssetDeleteView
(
DeleteView
):
model
=
Asset
...
...
@@ -119,10 +126,17 @@ class AssetModalListView(AdminUserRequiredMixin, ListView):
def
get_context_data
(
self
,
**
kwargs
):
group_id
=
self
.
request
.
GET
.
get
(
'group_id'
)
tag_id
=
self
.
request
.
GET
.
get
(
'tag_id'
)
if
group_id
:
group
=
AssetGroup
.
objects
.
get
(
id
=
group_id
)
context
=
{
'group_assets'
:[
x
.
id
for
x
in
group
.
assets
.
all
()]
'all_assets'
:[
x
.
id
for
x
in
group
.
assets
.
all
()]
}
kwargs
.
update
(
context
)
if
tag_id
:
tag
=
Tag
.
objects
.
get
(
id
=
tag_id
)
context
=
{
'all_assets'
:[
x
.
id
for
x
in
tag
.
asset_set
.
all
()]
}
kwargs
.
update
(
context
)
return
super
(
AssetModalListView
,
self
).
get_context_data
(
**
kwargs
)
...
...
@@ -150,7 +164,6 @@ class AssetGroupCreateView(AdminUserRequiredMixin, CreateView):
asset_group
=
form
.
save
()
assets_id_list
=
self
.
request
.
POST
.
getlist
(
'assets'
,
[])
assets
=
[
get_object_or_404
(
Asset
,
id
=
int
(
asset_id
))
for
asset_id
in
assets_id_list
]
print
assets
asset_group
.
created_by
=
self
.
request
.
user
.
username
or
'Admin'
asset_group
.
assets
.
add
(
*
tuple
(
assets
))
asset_group
.
save
()
...
...
@@ -161,6 +174,7 @@ class AssetGroupListView(AdminUserRequiredMixin, ListView):
paginate_by
=
settings
.
CONFIG
.
DISPLAY_PER_PAGE
context_object_name
=
'asset_group_list'
template_name
=
'assets/asset_group_list.html'
ordering
=
'-id'
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
...
...
@@ -569,3 +583,94 @@ class TagView(ListView):
def
get_context_data
(
self
,
**
kwargs
):
kwargs
[
'tag_list'
]
=
[(
i
.
id
,
i
.
name
,
i
.
asset_set
.
all
().
count
()
)
for
i
in
Tag
.
objects
.
all
().
order_by
(
'name'
)]
return
super
(
TagView
,
self
).
get_context_data
(
**
kwargs
)
class
TagsListView
(
AdminUserRequiredMixin
,
ListView
):
model
=
Tag
paginate_by
=
settings
.
CONFIG
.
DISPLAY_PER_PAGE
context_object_name
=
'asset_tags_list'
template_name
=
'assets/asset_tags_list.html'
ordering
=
'-id'
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
'app'
:
_
(
'Tag'
),
'action'
:
_
(
'Asset Tags list'
),
'keyword'
:
self
.
request
.
GET
.
get
(
'keyword'
,
''
)
}
kwargs
.
update
(
context
)
return
super
(
TagsListView
,
self
).
get_context_data
(
**
kwargs
)
class
AssetTagCreateView
(
AdminUserRequiredMixin
,
CreateView
):
model
=
Tag
form_class
=
AssetTagForm
template_name
=
'assets/asset_tag_create.html'
success_url
=
reverse_lazy
(
'assets:asset-tag-list'
)
#ordering = '-id'
# Todo: Asset group create template select assets so hard, need be resolve next
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
'app'
:
_
(
'Tag'
),
'action'
:
_
(
'Asset Tags list'
),
'assets_count'
:
0
,
}
kwargs
.
update
(
context
)
return
super
(
AssetTagCreateView
,
self
).
get_context_data
(
**
kwargs
)
def
form_valid
(
self
,
form
):
asset_tag
=
form
.
save
()
assets_id_list
=
self
.
request
.
POST
.
getlist
(
'assets'
,
[])
assets
=
[
get_object_or_404
(
Asset
,
id
=
int
(
asset_id
))
for
asset_id
in
assets_id_list
]
asset_tag
.
created_by
=
self
.
request
.
user
.
username
or
'Admin'
asset_tag
.
asset_set
.
add
(
*
tuple
(
assets
))
asset_tag
.
save
()
return
super
(
AssetTagCreateView
,
self
).
form_valid
(
form
)
class
AssetTagDetailView
(
SingleObjectMixin
,
AdminUserRequiredMixin
,
ListView
):
template_name
=
'assets/asset_tag_detail.html'
paginate_by
=
settings
.
CONFIG
.
DISPLAY_PER_PAGE
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
self
.
object
=
self
.
get_object
(
queryset
=
Tag
.
objects
.
all
())
return
super
(
AssetTagDetailView
,
self
).
get
(
request
,
*
args
,
**
kwargs
)
def
get_queryset
(
self
):
return
self
.
object
.
asset_set
.
all
()
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
'app'
:
_
(
'Tag'
),
'action'
:
_
(
'Asset Tags detail'
),
'asset_tag'
:
self
.
object
,
}
kwargs
.
update
(
context
)
return
super
(
AssetTagDetailView
,
self
).
get_context_data
(
**
kwargs
)
class
AssetTagUpdateView
(
AdminUserRequiredMixin
,
UpdateView
):
model
=
Tag
form_class
=
AssetTagForm
template_name
=
'assets/asset_tag_create.html'
success_url
=
reverse_lazy
(
'assets:asset-tag-list'
)
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
self
.
object
=
self
.
get_object
(
queryset
=
Tag
.
objects
.
all
())
return
super
(
AssetTagUpdateView
,
self
).
get
(
request
,
*
args
,
**
kwargs
)
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
'app'
:
_
(
'Tag'
),
'action'
:
_
(
'Asset Tags detail'
),
'assets_count'
:
self
.
object
.
asset_set
.
all
().
count
(),
'tag_id'
:
self
.
object
.
id
,
}
kwargs
.
update
(
context
)
return
super
(
AssetTagUpdateView
,
self
).
get_context_data
(
**
kwargs
)
class
AssetTagDeleteView
(
AdminUserRequiredMixin
,
DeleteView
):
template_name
=
'assets/delete_confirm.html'
model
=
Tag
success_url
=
reverse_lazy
(
'assets:asset-tag-list'
)
apps/templates/_nav.html
浏览文件 @
b99b88a3
...
...
@@ -23,7 +23,7 @@
<li
id=
"idc"
><a
href=
"{% url 'assets:idc-list' %}"
>
{% trans 'IDC' %}
</a></li>
<li
id=
"admin-user"
><a
href=
"{% url 'assets:admin-user-list' %}"
>
{% trans 'Admin user' %}
</a></li>
<li
id=
"system-user"
><a
href=
"{% url 'assets:system-user-list' %}"
>
{% trans 'System user' %}
</a></li>
<li
id=
"
"
><a
href=
"
"
>
{% trans 'Label' %}
</a></li>
<li
id=
"
asset-tag"
><a
href=
"{% url 'assets:asset-tag-list' %}
"
>
{% trans 'Label' %}
</a></li>
</ul>
</li>
<li
id=
"perms"
>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录