Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
jumpserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
jumpserver
Commits
d2e98940
Commit
d2e98940
authored
Sep 22, 2016
by
江世峰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update assets-group
parent
22089282
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
174 additions
and
30 deletions
+174
-30
api.py
apps/assets/api.py
+5
-5
forms.py
apps/assets/forms.py
+1
-1
asset_group_create.html
apps/assets/templates/assets/asset_group_create.html
+69
-18
asset_modal_list.html
apps/assets/templates/assets/asset_modal_list.html
+66
-0
idc_list.html
apps/assets/templates/assets/idc_list.html
+0
-3
urls.py
apps/assets/urls.py
+11
-1
utils.py
apps/assets/utils.py
+2
-1
views.py
apps/assets/views.py
+20
-1
jumpserver0921.rar
jumpserver0921.rar
+0
-0
No files found.
apps/assets/api.py
View file @
d2e98940
# ~*~ coding: utf-8 ~*~
from
rest_framework
import
serializers
from
rest_framework
import
viewsets
,
serializers
from
rest_framework
import
viewsets
,
serializers
,
generics
from
.models
import
AssetGroup
,
Asset
,
IDC
,
AssetExtend
...
...
@@ -45,9 +44,11 @@ class AssetViewSet(viewsets.ModelViewSet):
serializer_class
=
AssetSerializer
class
IDCViewSet
(
viewsets
.
ModelViewSet
):
class
IDCViewSet
(
viewsets
.
ReadOnly
ModelViewSet
):
"""
API endpoint that allows IDC to be viewed or edited.
"""
queryset
=
IDC
.
objects
.
all
()
serializer_class
=
IDCSerializer
\ No newline at end of file
serializer_class
=
IDCSerializer
apps/assets/forms.py
View file @
d2e98940
...
...
@@ -91,7 +91,7 @@ class AssetGroupForm(forms.ModelForm):
class
Meta
:
model
=
AssetGroup
fields
=
[
"name"
,
"comment"
,
"system_users"
"name"
,
"comment"
,
"system_users"
,
]
widgets
=
{
'name'
:
forms
.
TextInput
(
attrs
=
{}),
...
...
apps/assets/templates/assets/asset_group_create.html
View file @
d2e98940
...
...
@@ -37,18 +37,16 @@
{{ form.name|bootstrap_horizontal }}
{{ form.comment|bootstrap_horizontal }}
<div
class=
"hr-line-dashed"
></div>
<h3
class=
"widget-head-color-box"
>
资产
</h3>
<div
class=
"form-group"
>
<label
for=
"assets"
class=
"col-sm-2 control-label"
>
资产
</label>
<div
class=
"col-sm-9"
>
<select
name=
"assets"
id=
"assets"
data-placeholder=
"选择资产"
class=
"select2 form-control m-b"
multiple
tabindex=
"2"
>
{% for asset in assets %}
<option
value=
"{{ asset.id }}"
>
{{ asset.hostname }}
</option>
{% endfor %}
</select>
</div>
</div>
<!--{{ form.name|bootstrap_horizontal }}-->
<h3
class=
"widget-head-color-box"
>
资产数量
</h3>
<div
class=
"form-group"
>
<label
for=
"assets"
class=
"col-sm-2 control-label"
>
已有
</label>
<div
class=
"col-sm-9"
id=
"div1"
>
<button
type=
"button"
class=
"btn btn-info btn-rounded"
id=
"add_asset"
>
0
</button>
<!--<input type="text" value="" name="id_list" id="id_list"/>-->
</div>
</div>
<div
class=
"hr-line-dashed"
></div>
<h3
class=
"widget-head-color-box"
>
资产用户
</h3>
{{ form.system_users|bootstrap_horizontal }}
...
...
@@ -56,6 +54,7 @@
<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>
...
...
@@ -68,13 +67,64 @@
</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>
$
(
document
).
ready
(
function
()
{
$
(
'.select2'
).
select2
();
$
(
'.select2-system-user'
).
select2
();
})
</script>
<script
type=
"text/javascript"
>
$
(
function
(){
$
(
"#id_list"
).
val
(
""
);
});
$
(
document
).
ready
(
function
()
{
$
(
'.select2'
).
select2
();
$
(
'.select2-system-user'
).
select2
();
})
$
(
'#add_asset'
).
on
(
'click'
,
function
(){
//$('#box2').load("{% url 'assets:asset-modal-list' %}");
$
(
'#modal'
).
modal
(
'show'
);
});
$
(
'#modal'
).
modal
({
show
:
false
,
remote
:
"{% url 'assets:asset-modal-list' %}"
,
});
$
(
'#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('当远程数据加载完毕后,再触发;')
});
$
(
'#save-btn'
).
on
(
'click'
,
function
(){
alert
(
'点击保存按钮时触发;'
)
$
(
'#modal'
).
modal
(
'hide'
);
});
</script>
{% endblock %}
\ No newline at end of file
apps/assets/templates/assets/asset_modal_list.html
0 → 100644
View file @
d2e98940
<div
class=
"modal-header"
>
<button
type=
"button"
class=
"close"
data-dismiss=
"modal"
aria-hidden=
"true"
>
×
</button>
<h4
class=
"modal-title"
id=
"myModalLabel"
>
分配/回收资产
</h4>
</div>
<div
class=
"modal-body"
>
<table
class=
"table table-hover"
>
<thead>
<tr>
<th
class=
"text-center"
>
<input
type=
"checkbox"
id=
"check_all"
onclick=
"checkAll('check_all', 'checked')"
>
</th>
<th>
资产名称
</th>
<th>
IP
</th>
<th>
硬件类型
</th>
<th>
资产组
</th>
<th>
部门
</th>
</tr>
</thead>
<tbody>
{% for asset in asset_modal_list %}
<tr>
<td
class=
"text-center"
>
<input
type=
"checkbox"
name=
"checked"
value=
"{{ asset.id }}"
>
</td>
<td>
{{ asset.hostname }}
</td>
<td>
{{ asset.ip }}
</td>
<td>
虚拟机
</td>
<td>
网络设备
</td>
<td>
微信事业部
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<div
class=
"modal-footer"
>
<button
type=
"button"
class=
"btn btn-default"
id=
"close-btn"
>
关闭
</button>
<button
type=
"button"
class=
"btn btn-primary"
id=
"save-btn"
>
保存
</button>
</div>
<script
type=
"text/javascript"
>
$
(
'#close-btn'
).
on
(
'click'
,
function
(){
//alert('点击关闭按钮时触发;')
$
(
'#modal'
).
modal
(
'hide'
);
});
$
(
'#save-btn'
).
on
(
'click'
,
function
(){
// alert('点击保存按钮时触发2;')
var
box
=
$
(
"input[name='checked']:checked"
);
var
size
=
box
.
length
;
$
(
"#add_asset"
).
text
(
size
);
var
ids
=
[];
$
(
"#div1"
).
find
(
"input"
).
remove
();
for
(
var
i
=
0
;
i
<
box
.
length
;
i
++
){
var
value
=
$
(
box
[
i
]).
val
();
$
(
"#div1"
).
append
(
"<input type='hidden' name='assets' value='"
+
value
+
"'>"
);
}
$
(
'#modal'
).
modal
(
'hide'
);
});
</script>
apps/assets/templates/assets/idc_list.html
View file @
d2e98940
...
...
@@ -9,13 +9,10 @@
<th
class=
"text-center"
>
<input
type=
"checkbox"
id=
"check_all"
onclick=
"checkAll('check_all', 'checked')"
>
</th>
{#
<th
class=
"text-center"
>
{% trans 'ID' %}
</th>
#}
<th
class=
"text-center"
><a
href=
"{% url 'assets:idc-list' %}?sort=name"
>
{% trans 'Name' %}
</a></th>
<th
class=
"text-center"
>
{% trans 'Asset num' %}
</th>
{#
<th
class=
"text-center"
>
{% trans 'Bandwidth' %}
</th>
#}
<th
class=
"text-center"
>
{% trans 'Contact' %}
</th>
<th
class=
"text-center"
>
{% trans 'Phone' %}
</th>
{#
<th
class=
"text-center"
>
{% trans 'Address' %}
</th>
#}
<th
class=
"text-center"
>
{% trans 'operation' %}
</th>
{% endblock %}
...
...
apps/assets/urls.py
View file @
d2e98940
# coding:utf-8
from
django.conf.urls
import
url
,
include
import
views
import
api
# from .api import (
# AssetGroupViewSet, AssetViewSet, IDCViewSet
# )
...
...
@@ -19,6 +20,7 @@ urlpatterns = [
url
(
r'^asset/(?P<pk>[0-9]+)$'
,
views
.
AssetDetailView
.
as_view
(),
name
=
'asset-detail'
),
url
(
r'^asset/(?P<pk>[0-9]+)/update'
,
views
.
AssetUpdateView
.
as_view
(),
name
=
'asset-update'
),
url
(
r'^asset/(?P<pk>[0-9]+)/delete$'
,
views
.
AssetDeleteView
.
as_view
(),
name
=
'asset-delete'
),
url
(
r'^asset-modal$'
,
views
.
AssetModalListView
.
as_view
(),
name
=
'asset-modal-list'
),
# Resource asset group url
url
(
r'^asset-group$'
,
views
.
AssetGroupListView
.
as_view
(),
name
=
'asset-group-list'
),
...
...
@@ -50,5 +52,13 @@ urlpatterns = [
url
(
r'^system-user/(?P<pk>[0-9]+)/asset$'
,
views
.
SystemUserAssetView
.
as_view
(),
name
=
'system-user-asset'
),
# url(r'^system-user/(?P<pk>[0-9]+)/asset-group$', views.SystemUserAssetGroupView.as_view(),
# name='system-user-asset-group'),
# url(r'^api/v1.0/', include(router.urls)),
]
urlpatterns
+=
[
#json
url
(
r'^v1/assets/$'
,
api
.
AssetViewSet
.
as_view
({
'get'
:
'list'
}),
name
=
'assets-list-api'
),
url
(
r'^v1/idc/$'
,
api
.
IDCViewSet
.
as_view
({
'get'
:
'list'
}),
name
=
'idc-list-json'
),
]
apps/assets/utils.py
View file @
d2e98940
# ~*~ coding: utf-8 ~*~
#
from
rest_framework
import
serializers
from
models
import
Asset
apps/assets/views.py
View file @
d2e98940
...
...
@@ -100,6 +100,11 @@ class AssetDetailView(DetailView):
kwargs
.
update
(
context
)
return
super
(
AssetDetailView
,
self
)
.
get_context_data
(
**
kwargs
)
class
AssetModalListView
(
AdminUserRequiredMixin
,
ListView
):
paginate_by
=
settings
.
CONFIG
.
DISPLAY_PER_PAGE
model
=
Asset
context_object_name
=
'asset_modal_list'
template_name
=
'assets/asset_modal_list.html'
class
AssetGroupCreateView
(
AdminUserRequiredMixin
,
CreateView
):
model
=
AssetGroup
...
...
@@ -119,11 +124,22 @@ class AssetGroupCreateView(AdminUserRequiredMixin, CreateView):
kwargs
.
update
(
context
)
return
super
(
AssetGroupCreateView
,
self
)
.
get_context_data
(
**
kwargs
)
# def form_valid(self, form):
# asset_group = form.save()
# assets_id_list = self.request.POST.getlist('assets', [])
# assets = [get_object_or_404(Asset, id=asset_id) for asset_id in assets_id_list]
# asset_group.created_by = self.request.user.username or 'Admin'
# asset_group.assets.add(*tuple(assets))
# asset_group.save()
# return super(AssetGroupCreateView, self).form_valid(form)
def
form_valid
(
self
,
form
):
asset_group
=
form
.
save
()
assets_id_list
=
self
.
request
.
POST
.
getlist
(
'assets'
,
[])
assets
=
[
get_object_or_404
(
Asset
,
id
=
asset_id
)
for
asset_id
in
assets_id_list
]
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
()
...
...
@@ -283,6 +299,7 @@ class IDCDeleteView(AdminUserRequiredMixin, DeleteView):
success_url
=
reverse_lazy
(
'assets:idc-list'
)
class
AdminUserListView
(
AdminUserRequiredMixin
,
ListView
):
model
=
AdminUser
paginate_by
=
settings
.
CONFIG
.
DISPLAY_PER_PAGE
...
...
@@ -527,3 +544,5 @@ class SystemUserAssetView(AdminUserRequiredMixin, SingleObjectMixin, ListView):
# kwargs.update(context)
# return super(SystemUserAssetGroupView, self).get_context_data(**kwargs)
jumpserver0921.rar
0 → 100644
View file @
d2e98940
File added
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment