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
968b1b4c
Commit
968b1b4c
authored
Nov 06, 2016
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Stash
parent
afb92373
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
627 additions
and
152 deletions
+627
-152
api.py
apps/assets/api.py
+33
-26
models.py
apps/assets/models.py
+1
-0
serializers.py
apps/assets/serializers.py
+39
-4
admin_user_list.html
apps/assets/templates/assets/admin_user_list.html
+114
-37
asset_list.html
apps/assets/templates/assets/asset_list.html
+19
-18
delete_confirm.html
apps/assets/templates/assets/delete_confirm.html
+1
-1
idc_assets.html
apps/assets/templates/assets/idc_assets.html
+139
-0
idc_detail.html
apps/assets/templates/assets/idc_detail.html
+139
-0
idc_list.html
apps/assets/templates/assets/idc_list.html
+68
-34
urls.py
apps/assets/urls.py
+44
-10
views.py
apps/assets/views.py
+28
-20
flash_message_standalone.html
apps/templates/flash_message_standalone.html
+0
-0
models.py
apps/users/models.py
+1
-1
user_list.html
apps/users/templates/users/user_list.html
+1
-1
No files found.
apps/assets/api.py
View file @
968b1b4c
# ~*~ coding: utf-8 ~*~
from
rest_framework
import
serializers
from
rest_framework
import
viewsets
,
serializers
,
generics
from
rest_framework
import
viewsets
,
generics
,
mixins
from
rest_framework.response
import
Response
from
rest_framework.views
import
APIView
from
rest_framework_bulk
import
BulkListSerializer
,
BulkSerializerMixin
,
ListBulkCreateUpdateDestroyAPIView
from
django.shortcuts
import
get_object_or_404
from
common.mixins
import
BulkDeleteApiMixin
from
common.utils
import
get_object_or_none
,
signer
from
.hands
import
IsSuperUserOrTerminalUser
,
IsSuperUser
from
.models
import
AssetGroup
,
Asset
,
IDC
,
SystemUser
from
.serializers
import
AssetBulkUpdateSerializer
class
AssetGroupSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
AssetGroup
class
AssetSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
Asset
# fields = ('id', 'title', 'code', 'linenos', 'language', 'style')
class
IDCSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
IDC
# fields = ('id', 'title', 'code', 'linenos', 'language', 'style')
from
.models
import
AssetGroup
,
Asset
,
IDC
,
SystemUser
,
AdminUser
from
.
import
serializers
class
AssetGroupViewSet
(
viewsets
.
ModelViewSet
):
...
...
@@ -35,26 +18,50 @@ class AssetGroupViewSet(viewsets.ModelViewSet):
some other comment
"""
queryset
=
AssetGroup
.
objects
.
all
()
serializer_class
=
AssetGroupSerializer
serializer_class
=
serializers
.
AssetGroupSerializer
class
AssetViewSet
(
viewsets
.
ModelViewSet
):
"""API endpoint that allows Asset to be viewed or edited."""
queryset
=
Asset
.
objects
.
all
()
serializer_class
=
AssetSerializer
serializer_class
=
serializers
.
AssetSerializer
class
IDCViewSet
(
viewsets
.
ReadOnly
ModelViewSet
):
class
IDCViewSet
(
viewsets
.
ModelViewSet
):
"""API endpoint that allows IDC to be viewed or edited."""
queryset
=
IDC
.
objects
.
all
()
serializer_class
=
IDCSerializer
serializer_class
=
serializers
.
IDCSerializer
permission_classes
=
(
IsSuperUser
,)
class
AdminUserViewSet
(
viewsets
.
ModelViewSet
):
queryset
=
AdminUser
.
objects
.
all
()
serializer_class
=
serializers
.
AdminUserSerializer
permission_classes
=
(
IsSuperUser
,)
class
SystemUserViewSet
(
viewsets
.
ModelViewSet
):
queryset
=
SystemUser
.
objects
.
all
()
serializer_class
=
serializers
.
SystemUserSerializer
permission_classes
=
(
IsSuperUser
,)
class
IDCAssetsApi
(
generics
.
ListAPIView
):
model
=
IDC
serializer_class
=
serializers
.
AssetSerializer
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
filter_kwargs
=
{
self
.
lookup_field
:
self
.
kwargs
[
self
.
lookup_field
]}
self
.
object
=
get_object_or_404
(
self
.
model
,
**
filter_kwargs
)
return
super
(
IDCAssetsApi
,
self
)
.
get
(
request
,
*
args
,
**
kwargs
)
def
get_queryset
(
self
):
return
self
.
object
.
assets
.
all
()
class
AssetListUpdateApi
(
BulkDeleteApiMixin
,
ListBulkCreateUpdateDestroyAPIView
):
queryset
=
Asset
.
objects
.
all
()
serializer_class
=
AssetBulkUpdateSerializer
serializer_class
=
serializers
.
AssetBulkUpdateSerializer
permission_classes
=
(
IsSuperUser
,)
...
...
apps/assets/models.py
View file @
968b1b4c
...
...
@@ -329,6 +329,7 @@ class Asset(models.Model):
def
__unicode__
(
self
):
return
'
%(ip)
s:
%(port)
s'
%
{
'ip'
:
self
.
ip
,
'port'
:
self
.
port
}
@property
def
is_valid
(
self
):
warning
=
''
if
not
self
.
is_active
:
...
...
apps/assets/serializers.py
View file @
968b1b4c
# -*- coding: utf-8 -*-
from
django.utils.translation
import
ugettext_lazy
as
_
from
rest_framework
import
viewsets
,
serializers
,
generics
from
.models
import
AssetGroup
,
Asset
,
IDC
,
AssetExtend
from
.models
import
AssetGroup
,
Asset
,
IDC
,
AssetExtend
,
AdminUser
,
SystemUser
from
common.mixins
import
BulkDeleteApiMixin
from
rest_framework_bulk
import
BulkListSerializer
,
BulkSerializerMixin
...
...
@@ -14,11 +14,47 @@ class AssetBulkUpdateSerializer(BulkSerializerMixin, serializers.ModelSerializer
class
Meta
(
object
):
model
=
Asset
list_serializer_class
=
BulkListSerializer
fields
=
[
'id'
,
'port'
,
'idc'
]
fields
=
(
'id'
,
'port'
,
'idc'
)
# def get_group_display(self, obj):
# return " ".join([group.name for group in obj.groups.all()])
#
# def get_active_display(self, obj):
# # TODO: user ative state
# return not (obj.is_expired and obj.is_active)
\ No newline at end of file
# return not (obj.is_expired and obj.is_active)
class
AssetGroupSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
AssetGroup
class
AssetSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
Asset
class
AdminUserSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
AdminUser
class
SystemUserSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
SystemUser
class
IDCSerializer
(
serializers
.
ModelSerializer
):
assets_amount
=
serializers
.
SerializerMethodField
()
class
Meta
:
model
=
IDC
@staticmethod
def
get_assets_amount
(
obj
):
return
obj
.
assets
.
count
()
def
get_field_names
(
self
,
declared_fields
,
info
):
fields
=
super
(
IDCSerializer
,
self
)
.
get_field_names
(
declared_fields
,
info
)
fields
.
append
(
'assets_amount'
)
return
fields
apps/assets/templates/assets/admin_user_list.html
View file @
968b1b4c
{% extends '_base_list.html' %}
{% load i18n %}
{% load common_tags %}
{% block content_left_head %}
<a
href=
"{% url 'assets:admin-user-create' %}"
class=
"btn btn-sm btn-primary "
>
{% trans "Create admin user" %}
</a>
{% endblock %}
{#{% load i18n %}#}
{#{% load common_tags %}#}
{#{% block content_left_head %}#}
{#
<a
href=
"{% url 'assets:admin-user-create' %}"
class=
"btn btn-sm btn-primary "
>
{% trans "Create admin user" %}
</a>
#}
{#{% endblock %}#}
{##}
{#{% block table_head %}#}
{#
<th
class=
"text-center"
>
{% trans 'ID' %}
</th>
#}
{#
<th
class=
"text-center"
><a
href=
"{% url 'assets:admin-user-list' %}?sort=name"
>
{% trans 'Name' %}
</a></th>
#}
{#
<th
class=
"text-center"
><a
href=
"{% url 'assets:admin-user-list' %}?sort=username"
>
{% trans 'Username' %}
</a></th>
#}
{#
<th
class=
"text-center"
>
{% trans 'Asset num' %}
</th>
#}
{#
<th
class=
"text-center"
>
{% trans 'Lost connection' %}
</th>
#}
{#
<th
class=
"text-center"
>
{% trans 'Comment' %}
</th>
#}
{#
<th
class=
"text-center"
></th>
#}
{#{% endblock %}#}
{##}
{#{% block table_body %}#}
{# {% for admin_user in admin_user_list %}#}
{#
<tr
class=
"gradeX"
>
#}
{#
<td
class=
"text-center"
>
{{ admin_user.id }}
</td>
#}
{#
<td>
#}
{#
<a
href=
"{% url 'assets:admin-user-detail' pk=admin_user.id %}"
>
#}
{# {{ admin_user.name }}#}
{#
</a>
#}
{#
</td>
#}
{#
<td
class=
"text-center"
>
{{ admin_user.username }}
</td>
#}
{#
<td
class=
"text-center"
>
{{ admin_user.assets.count }}
</td>
#}
{#
<td
class=
"text-center"
>
{{ admin_user.assets.count }}
</td>
#}
{#
<td
class=
"text-center"
>
{{ admin_user.comment|truncatewords:8 }}
</td>
#}
{#
<td
class=
"text-center"
>
#}
{#
<!-- Todo: Click script button will paste a url to clipboard like: curl http://url/admin_user_create.sh | bash -->
#}
{#
<a
href=
"{% url 'assets:admin-user-update' pk=admin_user.id %}"
class=
"btn btn-xs btn-primary"
>
{% trans 'Script' %}
</a>
#}
{#
<!-- Todo: Click refresh button will run a task to test admin user could connect asset or not immediately -->
#}
{#
<a
href=
"{% url 'assets:admin-user-update' pk=admin_user.id %}"
class=
"btn btn-xs btn-warning"
>
{% trans 'Refresh' %}
</a>
#}
{#
<a
href=
"{% url 'assets:admin-user-update' pk=admin_user.id %}"
class=
"btn btn-xs btn-info"
>
{% trans 'Update' %}
</a>
#}
{#
<a
onclick=
"obj_del(this,'{{ admin_user.name }}','{% url 'assets:admin-user-delete' admin_user.id %}')"
class=
"btn btn-xs btn-danger del"
>
{% trans 'Delete' %}
</a>
#}
{#
</td>
#}
{#
</tr>
#}
{# {% endfor %}#}
{#{% endblock %}#}
{% extends '_base_list.html' %}
{% load i18n static %}
{% block custom_head_css_js %}
{{ block.super }}
<style>
div
.dataTables_wrapper
div
.dataTables_filter
,
.dataTables_length
{
float
:
right
!important
;
}
{% block table_head %}
<th
class=
"text-center"
>
{% trans 'ID' %}
</th>
<th
class=
"text-center"
><a
href=
"{% url 'assets:admin-user-list' %}?sort=name"
>
{% trans 'Name' %}
</a></th>
<th
class=
"text-center"
><a
href=
"{% url 'assets:admin-user-list' %}?sort=username"
>
{% trans 'Username' %}
</a></th>
<th
class=
"text-center"
>
{% trans 'Asset num' %}
</th>
<th
class=
"text-center"
>
{% trans 'Lost connection' %}
</th>
<th
class=
"text-center"
>
{% trans 'Comment' %}
</th>
<th
class=
"text-center"
></th>
div
.dataTables_wrapper
div
.dataTables_filter
{
margin-left
:
15px
;
}
</style>
{% endblock %}
{% block table_body %}
{% for admin_user in admin_user_list %}
<tr
class=
"gradeX"
>
<td
class=
"text-center"
>
{{ admin_user.id }}
</td>
<td>
<a
href=
"{% url 'assets:admin-user-detail' pk=admin_user.id %}"
>
{{ admin_user.name }}
</a>
</td>
<td
class=
"text-center"
>
{{ admin_user.username }}
</td>
<td
class=
"text-center"
>
{{ admin_user.assets.count }}
</td>
<td
class=
"text-center"
>
{{ admin_user.assets.count }}
</td>
<td
class=
"text-center"
>
{{ admin_user.comment|truncatewords:8 }}
</td>
<td
class=
"text-center"
>
<!-- Todo: Click script button will paste a url to clipboard like: curl http://url/admin_user_create.sh | bash -->
<a
href=
"{% url 'assets:admin-user-update' pk=admin_user.id %}"
class=
"btn btn-xs btn-primary"
>
{% trans 'Script' %}
</a>
<!-- Todo: Click refresh button will run a task to test admin user could connect asset or not immediately -->
<a
href=
"{% url 'assets:admin-user-update' pk=admin_user.id %}"
class=
"btn btn-xs btn-warning"
>
{% trans 'Refresh' %}
</a>
<a
href=
"{% url 'assets:admin-user-update' pk=admin_user.id %}"
class=
"btn btn-xs btn-info"
>
{% trans 'Update' %}
</a>
<a
onclick=
"obj_del(this,'{{ admin_user.name }}','{% url 'assets:admin-user-delete' admin_user.id %}')"
class=
"btn btn-xs btn-danger del"
>
{% trans 'Delete' %}
</a>
</td>
</tr>
{% endfor %}
{% block table_search %}{% endblock %}
{% block table_container %}
<div
class=
"uc pull-left m-l-5 m-r-5"
>
<a
href=
"{% url "
assets:idc-create
"
%}"
class=
"btn btn-sm btn-primary"
>
{% trans "Create IDC" %}
</a>
</div>
<table
class=
"table table-striped table-bordered table-hover "
id=
"admin_user_list_table"
>
<thead>
<tr>
<th
class=
"text-center"
>
<input
type=
"checkbox"
id=
"check_all"
class=
"ipt_check_all"
>
</th>
<th
class=
"text-center"
>
{% trans 'Name' %}
</th>
<th
class=
"text-center"
>
{% trans 'Username' %}
</th>
<th
class=
"text-center"
>
{% trans 'Asset num' %}
</th>
<th
class=
"text-center"
>
{% trans 'Lost connection' %}
</th>
<th
class=
"text-center"
>
{% trans 'Comment' %}
</th>
<th
class=
"text-center"
></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
{% endblock %}
{% block content_bottom_left %}{% endblock %}
{% block custom_foot_js %}
<script>
$
(
document
).
ready
(
function
(){
var
options
=
{
ele
:
$
(
'#admin_user_list_table'
),
columnDefs
:
[
{
targets
:
1
,
createdCell
:
function
(
td
,
cellData
,
rowData
)
{
var
detail_btn
=
'<a href="{% url "assets:admin-user-detail" pk=99991937 %}">'
+
cellData
+
'</a>'
;
$
(
td
).
html
(
detail_btn
.
replace
(
'99991937'
,
rowData
.
id
));
}},
{
#
{
targets
:
4
,
createdCell
:
function
(
td
,
cellData
)
{
#
}
{
#
var
innerHtml
=
cellData
.
length
>
8
?
cellData
.
substring
(
0
,
8
)
+
'...'
:
cellData
;
#
}
{
#
$
(
td
).
html
(
'<a href="javascript:void(0);" data-toggle="tooltip" title="'
+
cellData
+
'">'
+
innerHtml
+
'</a>'
);
#
}
{
#
}},
#
}
{
#
{
targets
:
6
,
createdCell
:
function
(
td
,
cellData
)
{
#
}
{
#
if
(
!
cellData
)
{
#
}
{
#
$
(
td
).
html
(
'<i class="fa fa-times text-danger"></i>'
)
#
}
{
#
}
else
{
#
}
{
#
$
(
td
).
html
(
'<i class="fa fa-check text-navy"></i>'
)
#
}
{
#
}
#
}
{
#
}},
#
}
{
targets
:
6
,
createdCell
:
function
(
td
,
cellData
,
rowData
)
{
var
update_btn
=
'<a href="{% url "assets:idc-update" pk=99991937 %}" class="btn btn-xs btn-info">{% trans "Update" %}</a>'
.
replace
(
'99991937'
,
cellData
);
var
del_btn
=
'<a class="btn btn-xs btn-danger m-l-xs btn_user_delete" data-uid="99991937">{% trans "Delete" %}</a>'
.
replace
(
'99991937'
,
cellData
);
$
(
td
).
html
(
update_btn
+
del_btn
)
}}],
ajax_url
:
'{% url "assets:idc-list-create-api" %}'
,
columns
:
[{
data
:
function
(){
return
""
}},
{
data
:
"name"
},
{
data
:
"assets_amount"
},
{
data
:
"contact"
},
{
data
:
"phone"
},
{
data
:
"operator"
},
{
data
:
"id"
}],
op_html
:
$
(
'#actions'
).
html
()
};
jumpserver
.
initDataTable
(
options
);
});
</script>
{% endblock %}
apps/assets/templates/assets/asset_list.html
View file @
968b1b4c
...
...
@@ -7,19 +7,19 @@
<script
src=
"{% static 'js/plugins/select2/select2.full.min.js' %}"
></script>
<style>
div
.dataTables_wrapper
div
.dataTables_filter
{
margin-left
:
15px
;
float
:
right
!important
;
}
div
.dataTables_wrapper
div
.dataTables_filter
,
.dataTables_length
{
float
:
right
!important
;
}
.custom
{
/*float:left;*/
margin-right
:
5px
;
div
.dataTables_wrapper
div
.dataTables_filter
{
margin-left
:
15px
;
float
:
right
!important
;
}
#modal
.modal-body
{
max-height
:
200px
;
}
div
.dataTables_wrapper
div
.dataTables_filter
,
.dataTables_length
{
float
:
right
!important
;
}
.custom
{
/*float:left;*/
margin-right
:
5px
;
}
#modal
.modal-body
{
max-height
:
200px
;
}
</style>
{% endblock %}
{% block content_left_head %}{% endblock %}
...
...
@@ -80,7 +80,8 @@ div.dataTables_wrapper div.dataTables_filter,
</td>
<td
class=
"text-center"
>
<a
href=
"{% url 'assets:asset-update' pk=asset.id %}"
class=
"btn btn-xs btn-info"
>
{% trans 'Update' %}
</a>
<a
onclick=
"objectDelete(this,'{{ asset.hostname }}','{% url 'assets:asset-delete' pk=asset.id %}')"
class=
"btn btn-xs btn-danger del"
>
{% trans 'Delete' %}
</a>
<a
onclick=
"objectDelete(this,'{{ asset.hostname }}','{% url 'assets:asset-detail-update-delete-api' pk=asset.id %}')"
class=
"btn btn-xs btn-danger del"
>
{% trans 'Delete' %}
</a>
</td>
</tr>
{% endfor %}
...
...
@@ -190,7 +191,7 @@ div.dataTables_wrapper div.dataTables_filter,
}
else
{
$
(
this
).
addClass
(
'selected'
);
this
.
children
[
0
].
children
[
0
].
checked
=
1
;
}
;
}
});
$
(
'#btn_bulk_update'
).
on
(
'click'
,
function
(){
...
...
@@ -201,7 +202,7 @@ div.dataTables_wrapper div.dataTables_filter,
for
(
var
i
=
0
;
i
<
column2
.
length
;
i
++
){
id_list
.
push
({
id
:
column2
[
i
].
id
,
hostname
:
column2
[
i
].
ip
});
plain_id_list
.
push
(
parseInt
(
column2
[
i
].
id
));
}
;
}
var
url_delete
=
the_url
+
'?id__in='
+
JSON
.
stringify
(
plain_id_list
);
//APIUpdateAttr({url: url_delete, method: 'DELETE', success: success, error: fail});
...
...
@@ -227,18 +228,18 @@ div.dataTables_wrapper div.dataTables_filter,
}
});
});
}
;
}
function
doUpdate
()
{
// alert(plain_id_list);
// $('#asset_bulk_update_modal').modal('show');
window
.
location
.
href
=
"{% url 'assets:asset-modal-update' %}?plain_id_lists="
+
plain_id_list
}
;
}
var
action
=
$
(
'#slct_bulk_update option:selected'
).
val
();
if
(
id_list
.
length
===
0
)
{
action
=
'default'
;
}
;
}
switch
(
action
)
{
case
'deactive'
:
alert
(
action
+
"未完成"
);
...
...
apps/assets/templates/assets/delete_confirm.html
View file @
968b1b4c
...
...
@@ -8,7 +8,7 @@
<body>
<form
action=
""
method=
"post"
>
{% csrf_token %}
<p>
Are you sure you want to delete "{{ object.name }}"
?
</p>
<p>
{% trans 'Are you sure delete' %}
<b>
{{ object.name }}
</b>
?
</p>
<input
type=
"submit"
value=
"Confirm"
/>
</form>
</body>
...
...
apps/assets/templates/assets/idc_assets.html
0 → 100644
View file @
968b1b4c
{% 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>
<style>
div
.dataTables_wrapper
div
.dataTables_filter
,
.dataTables_length
{
float
:
right
!important
;
}
div
.dataTables_wrapper
div
.dataTables_filter
{
margin-left
:
15px
;
}
</style>
{% 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>
<a
href=
"{% url 'assets:idc-detail' pk=idc.id %}"
class=
"text-center"
><i
class=
"fa fa-laptop"
></i>
{% trans 'Detail' %}
</a>
</li>
<li
class=
"active"
><a
href=
"{% url 'assets:idc-assets' pk=idc.id %}"
class=
"text-center"
>
<i
class=
"fa fa-bar-chart-o"
></i>
{% trans 'IDC assets' %}
</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
style=
"float: left"
>
{% trans 'IDC assets' %}
<b>
{{ idc.name }}
</b><span
class=
"badge"
></span></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-striped table-bordered table-hover "
id=
"idc_assets_table"
>
<thead>
<tr>
<th
class=
"text-center"
>
<input
type=
"checkbox"
id=
"check_all"
class=
"ipt_check_all"
>
</th>
<th>
{% trans 'Hostname' %}
</th>
<th>
{% trans 'IP' %}
</th>
<th>
{% trans 'Port' %}
</th>
<th>
{% trans 'Type' %}
</th>
<th>
{% trans 'Valid' %}
</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</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 'Attach to assets ' %}
</div>
<div
class=
"panel-body"
>
<table
class=
"table"
>
<tbody>
<form>
<tr
class=
"no-borders-tr"
>
<td
colspan=
"2"
>
<select
data-placeholder=
"{% trans 'Select asset' %}"
class=
"select2"
style=
"width: 100%"
multiple=
""
tabindex=
"4"
>
{% for asset in assets_remain %}
<option
value=
"{{ asset.id }}"
>
{{ asset.ip}}:{{ asset.port }}
</option>
{% endfor %}
</select>
</td>
</tr>
<tr
class=
"no-borders-tr"
>
<td
colspan=
"2"
>
<button
type=
"button"
class=
"btn btn-primary btn-sm"
>
{% trans 'Attach' %}
</button>
</td>
</tr>
</form>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
{% block custom_foot_js %}
<script>
$
(
document
).
ready
(
function
()
{
$
(
'.select2'
).
select2
();
var
options
=
{
ele
:
$
(
'#idc_assets_table'
),
buttons
:
[],
order
:
[],
columnDefs
:
[
{
targets
:
1
,
createdCell
:
function
(
td
,
cellData
,
rowData
)
{
var
detail_btn
=
'<a href="{% url "assets:asset-detail" pk=99991937 %}">'
+
cellData
+
'</a>'
;
$
(
td
).
html
(
detail_btn
.
replace
(
'99991937'
,
rowData
.
id
));
}},
{
targets
:
5
,
createdCell
:
function
(
td
,
cellData
)
{
if
(
!
cellData
)
{
$
(
td
).
html
(
'<i class="fa fa-times text-danger"></i>'
)
}
else
{
$
(
td
).
html
(
'<i class="fa fa-check text-navy"></i>'
)
}
}}],
ajax_url
:
'{% url "assets:idc-assets-api" pk=idc.id %}'
,
columns
:
[{
data
:
function
(){
return
""
}},
{
data
:
"hostname"
},
{
data
:
"ip"
},
{
data
:
"port"
},
{
data
:
"type"
},
{
data
:
"is_active"
}]
};
jumpserver
.
initDataTable
(
options
);
});
</script>
{% endblock %}
\ No newline at end of file
apps/assets/templates/assets/idc_detail.html
0 → 100644
View file @
968b1b4c
{% 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=
"{% url 'assets:idc-detail' pk=idc.id %}"
class=
"text-center"
><i
class=
"fa fa-laptop"
></i>
{% trans 'Detail' %}
</a>
</li>
<li>
<a
href=
"{% url 'assets:idc-assets' pk=idc.id %}"
class=
"text-center"
>
<i
class=
"fa fa-bar-chart-o"
></i>
{% trans 'IDC assets' %}
</a>
</li>
<li
class=
"pull-right"
>
<a
class=
"btn btn-outline btn-default"
href=
"{% url 'assets:idc-update' pk=idc.id %}"
><i
class=
"fa fa-edit"
></i>
Update
</a>
</li>
<li
class=
"pull-right"
>
<a
class=
"btn btn-outline btn-danger"
href=
"{% url 'assets:idc-delete' pk=idc.id %}"
>
<i
class=
"fa fa-edit"
></i>
Delete
</a>
</li>
</ul>
</div>
<div
class=
"tab-content"
>
<div
class=
"col-sm-9"
style=
"padding-left: 0;"
>
<div
class=
"ibox float-e-margins"
>
<div
class=
"ibox-title"
>
<span
class=
"label"
><b>
{{ idc.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 'Name' %}:
</td>
<td><b>
{{ idc.name }}
</b></td>
</tr>
<tr>
<td>
{% trans 'Bandwidth' %}:
</td>
<td><b>
{{ idc.bandwidth }}
</b></td>
</tr>
<tr>
<td>
{% trans 'Contact' %}:
</td>
<td><b>
{{ idc.contact }}
</b></td>
</tr>
<tr>
<td>
{% trans 'Phone' %}:
</td>
<td><b>
{{ idc.phone }}
</b></td>
</tr>
<tr>
<td>
{% trans 'Address' %}:
</td>
<td><b>
{{ idc.address }}
</b></td>
</tr>
<tr>
<td>
{% trans 'Intranet' %}:
</td>
<td><b>
{{ idc.Intranet }}
</b></td>
</tr>
<tr>
<td>
{% trans 'Extranet' %}:
</td>
<td><b>
{{ idc.extranet }}
</b></td>
</tr>
<tr>
<td>
{% trans 'Operator' %}:
</td>
<td><b>
{{ idc.operator }}
</b></td>
</tr>
<tr>
<td>
{% trans 'Date created' %}:
</td>
<td><b>
{{ system_user.date_created }}
</b></td>
</tr>
<tr>
<td>
{% trans 'Created by' %}:
</td>
<td><b>
{{ asset_group.created_by }}
</b></td>
</tr>
<tr>
<td>
{% trans 'Comment' %}:
</td>
<td><b>
{{ system_user.comment }}
</b></td>
</tr>
</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/idc_list.html
View file @
968b1b4c
{% extends '_base_list.html' %}
{% load i18n %}
{% load common_tags %}
{% block content_left_head %}
<a
href=
"{% url 'assets:idc-create' %}"
class=
"btn btn-sm btn-primary "
>
{% trans "Create IDC" %}
</a>
{% endblock %}
{% load i18n static %}
{% block custom_head_css_js %}
{{ block.super }}
<style>
div
.dataTables_wrapper
div
.dataTables_filter
,
.dataTables_length
{
float
:
right
!important
;
}
{% 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:idc-list' %}?sort=name"
>
{% trans 'Name' %}
</a></th>
<th
class=
"text-center"
>
{% trans 'Asset num' %}
</th>
<th
class=
"text-center"
>
{% trans 'Contact' %}
</th>
<th
class=
"text-center"
>
{% trans 'Phone' %}
</th>
<th
class=
"text-center"
>
{% trans 'operation' %}
</th>
div
.dataTables_wrapper
div
.dataTables_filter
{
margin-left
:
15px
;
}
</style>
{% endblock %}
{% block table_body %}
{% for idc in idc_list %}
<tr
class=
"gradeX"
>
<td
class=
"text-center"
>
<input
type=
"checkbox"
name=
"checked"
value=
"{{ idc.id }}"
>
</td>
<td
class=
"text-center"
>
{{ idc.name }}
</td>
<td
class=
"text-center"
>
{{ idc.assets.count }}
</td>
{#
<td
class=
"text-center"
>
{{ idc.bandwidth }}
</td>
#}
<td
class=
"text-center"
>
{{ idc.contact }}
</td>
<td
class=
"text-center"
>
{{ idc.phone }}
</td>
{#
<td
class=
"text-center"
>
{{ idc.address }}
</td>
#}
<td
class=
"text-center"
>
<a
href=
"{% url 'assets:idc-update' pk=idc.id %}"
class=
"btn btn-xs btn-info"
>
{% trans 'Update' %}
</a>
<a
onclick=
"objectDelete(this, '{{ idc.name }}', '{% url 'assets:idc-delete' idc.id %}')"
class=
"btn btn-xs btn-danger del"
>
{% trans 'Delete' %}
</a>
</td>
</tr>
{% endfor %}
{% block table_search %}{% endblock %}
{% block table_container %}
<div
class=
"uc pull-left m-l-5 m-r-5"
>
<a
href=
"{% url "
assets:idc-create
"
%}"
class=
"btn btn-sm btn-primary"
>
{% trans "Create IDC" %}
</a>
</div>
<table
class=
"table table-striped table-bordered table-hover "
id=
"idc_list_table"
>
<thead>
<tr>
<th
class=
"text-center"
>
<input
type=
"checkbox"
id=
"check_all"
class=
"ipt_check_all"
>
</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 'Contact' %}
</th>
<th
class=
"text-center"
>
{% trans 'Phone' %}
</th>
<th
class=
"text-center"
>
{% trans 'Operator' %}
</th>
<th
class=
"text-center"
>
{% trans 'Action' %}
</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
{% endblock %}
{% block content_bottom_left %}{% endblock %}
{% block custom_foot_js %}
<script>
$
(
document
).
ready
(
function
(){
var
options
=
{
ele
:
$
(
'#idc_list_table'
),
columnDefs
:
[
{
targets
:
1
,
createdCell
:
function
(
td
,
cellData
,
rowData
)
{
var
detail_btn
=
'<a href="{% url "assets:idc-detail" pk=99991937 %}">'
+
cellData
+
'</a>'
;
$
(
td
).
html
(
detail_btn
.
replace
(
'99991937'
,
rowData
.
id
));
}},
{
#
{
targets
:
4
,
createdCell
:
function
(
td
,
cellData
)
{
#
}
{
#
var
innerHtml
=
cellData
.
length
>
8
?
cellData
.
substring
(
0
,
8
)
+
'...'
:
cellData
;
#
}
{
#
$
(
td
).
html
(
'<a href="javascript:void(0);" data-toggle="tooltip" title="'
+
cellData
+
'">'
+
innerHtml
+
'</a>'
);
#
}
{
#
}},
#
}
{
#
{
targets
:
6
,
createdCell
:
function
(
td
,
cellData
)
{
#
}
{
#
if
(
!
cellData
)
{
#
}
{
#
$
(
td
).
html
(
'<i class="fa fa-times text-danger"></i>'
)
#
}
{
#
}
else
{
#
}
{
#
$
(
td
).
html
(
'<i class="fa fa-check text-navy"></i>'
)
#
}
{
#
}
#
}
{
#
}},
#
}
{
targets
:
6
,
createdCell
:
function
(
td
,
cellData
,
rowData
)
{
var
update_btn
=
'<a href="{% url "assets:idc-update" pk=99991937 %}" class="btn btn-xs btn-info">{% trans "Update" %}</a>'
.
replace
(
'99991937'
,
cellData
);
var
del_btn
=
'<a class="btn btn-xs btn-danger m-l-xs btn_user_delete" data-uid="99991937">{% trans "Delete" %}</a>'
.
replace
(
'99991937'
,
cellData
);
$
(
td
).
html
(
update_btn
+
del_btn
)
}}],
ajax_url
:
'{% url "assets:idc-list-create-api" %}'
,
columns
:
[{
data
:
function
(){
return
""
}},
{
data
:
"name"
},
{
data
:
"assets_amount"
},
{
data
:
"contact"
},
{
data
:
"phone"
},
{
data
:
"operator"
},
{
data
:
"id"
}],
op_html
:
$
(
'#actions'
).
html
()
};
jumpserver
.
initDataTable
(
options
);
});
</script>
{% endblock %}
apps/assets/urls.py
View file @
968b1b4c
...
...
@@ -2,14 +2,8 @@
from
django.conf.urls
import
url
,
include
import
views
import
api
# from .api import (
# AssetGroupViewSet, AssetViewSet, IDCViewSet
# )
# from rest_framework import routers
# router = routers.DefaultRouter()
# router.register(r'assetgroup', AssetGroupViewSet)
# router.register(r'asset', AssetViewSet)
# router.register(r'idc', IDCViewSet)
from
rest_framework
import
routers
app_name
=
'assets'
urlpatterns
=
[
...
...
@@ -43,6 +37,7 @@ urlpatterns = [
url
(
r'^idc/(?P<pk>[0-9]+)$'
,
views
.
IDCDetailView
.
as_view
(),
name
=
'idc-detail'
),
url
(
r'^idc/(?P<pk>[0-9]+)/update'
,
views
.
IDCUpdateView
.
as_view
(),
name
=
'idc-update'
),
url
(
r'^idc/(?P<pk>[0-9]+)/delete$'
,
views
.
IDCDeleteView
.
as_view
(),
name
=
'idc-delete'
),
url
(
r'^idc/(?P<pk>[0-9]+)/assets$'
,
views
.
IDCAssetsView
.
as_view
(),
name
=
'idc-assets'
),
# Resource admin user url
url
(
r'^admin-user$'
,
views
.
AdminUserListView
.
as_view
(),
name
=
'admin-user-list'
),
...
...
@@ -63,10 +58,49 @@ urlpatterns = [
]
# router = routers.DefaultRouter()
# router.register(r'v1/asset-groups/', api.AssetGroupViewSet)
# router.register(r'v1/assets/', api.AssetViewSet)
# router.register(r'v1/idc/', api.IDCViewSet)
asset_list_view
=
api
.
AssetViewSet
.
as_view
({
'get'
:
'list'
,
'post'
:
'create'
})
asset_detail_view
=
api
.
AssetViewSet
.
as_view
({
'get'
:
'retrieve'
,
'put'
:
'update'
,
'patch'
:
'partial_update'
,
'delete'
:
'destroy'
,
})
idc_list_view
=
api
.
IDCViewSet
.
as_view
({
'get'
:
'list'
,
'post'
:
'create'
,
})
idc_detail_view
=
api
.
IDCViewSet
.
as_view
({
'get'
:
'retrieve'
,
'put'
:
'update'
,
'patch'
:
'partial_update'
,
'delete'
:
'destroy'
,
})
admin_user_list_view
=
api
.
AdminUserViewSet
.
as_view
({
'get'
:
'list'
,
'post'
:
'create'
,
})
urlpatterns
+=
[
url
(
r'^v1/assets/$'
,
api
.
AssetViewSet
.
as_view
({
'get'
:
'list'
}),
name
=
'assets-list-api'
),
url
(
r'^v1/assets/$'
,
asset_list_view
,
name
=
'asset-list-create-api'
),
url
(
r'^v1/assets/(?P<pk>[0-9]+)/$'
,
asset_detail_view
,
name
=
'asset-detail-update-delete-api'
),
url
(
r'^v1/assets_bulk/$'
,
api
.
AssetListUpdateApi
.
as_view
(),
name
=
'asset-bulk-update-api'
),
url
(
r'^v1/idc/$'
,
api
.
IDCViewSet
.
as_view
({
'get'
:
'list'
}),
name
=
'idc-list-json'
),
url
(
r'^v1/idc/$'
,
idc_list_view
,
name
=
'idc-list-create-api'
),
url
(
r'^v1/idc/(?P<pk>[0-9]+)/$'
,
idc_detail_view
,
name
=
'idc-detail-update-delete-api'
),
url
(
r'^v1/idc/(?P<pk>[0-9]+)/assets/$'
,
api
.
IDCAssetsApi
.
as_view
(),
name
=
'idc-assets-api'
),
url
(
r'^v1/admin-user/$'
,
idc_list_view
,
name
=
'idc-list-create-api'
),
url
(
r'^v1/idc/(?P<pk>[0-9]+)/$'
,
idc_detail_view
,
name
=
'idc-detail-update-delete-api'
),
url
(
r'^v1/system-user/auth/'
,
api
.
SystemUserAuthApi
.
as_view
(),
name
=
'system-user-auth'
),
]
...
...
apps/assets/views.py
View file @
968b1b4c
...
...
@@ -30,14 +30,14 @@ class AssetListView(AdminUserRequiredMixin, ListView):
@staticmethod
def
sorted_by_valid_and_ip
(
asset
):
ip_list
=
int_seq
(
asset
.
ip
.
split
(
'.'
))
ip_list
.
insert
(
0
,
asset
.
is_valid
()
[
0
])
ip_list
.
insert
(
0
,
asset
.
is_valid
[
0
])
return
ip_list
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
'app'
:
'Assets'
,
'action'
:
'asset list'
,
'tag_list'
:
[(
i
.
id
,
i
.
name
,
i
.
asset_set
.
all
()
.
count
())
for
i
in
Tag
.
objects
.
all
()
.
order_by
(
'name'
)]
'tag_list'
:
[(
i
.
id
,
i
.
name
,
i
.
asset_set
.
all
()
.
count
())
for
i
in
Tag
.
objects
.
all
()
.
order_by
(
'name'
)]
}
kwargs
.
update
(
context
)
...
...
@@ -341,33 +341,33 @@ class AssetGroupDeleteView(AdminUserRequiredMixin, DeleteView):
success_url
=
reverse_lazy
(
'assets:asset-group-list'
)
class
IDCListView
(
AdminUserRequiredMixin
,
List
View
):
model
=
IDC
paginate_by
=
settings
.
CONFIG
.
DISPLAY_PER_PAGE
context_object_name
=
'idc_list'
class
IDCListView
(
AdminUserRequiredMixin
,
Template
View
):
#
model = IDC
#
paginate_by = settings.CONFIG.DISPLAY_PER_PAGE
#
context_object_name = 'idc_list'
template_name
=
'assets/idc_list.html'
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
'app'
:
_
(
'Assets'
),
'action'
:
_
(
'IDC list'
),
'keyword'
:
self
.
request
.
GET
.
get
(
'keyword'
,
''
)
#
'keyword': self.request.GET.get('keyword', '')
}
kwargs
.
update
(
context
)
return
super
(
IDCListView
,
self
)
.
get_context_data
(
**
kwargs
)
def
get_queryset
(
self
):
self
.
queryset
=
super
(
IDCListView
,
self
)
.
get_queryset
()
self
.
keyword
=
keyword
=
self
.
request
.
GET
.
get
(
'keyword'
,
''
)
self
.
sort
=
sort
=
self
.
request
.
GET
.
get
(
'sort'
,
'-date_created'
)
if
keyword
:
self
.
queryset
=
self
.
queryset
.
filter
(
Q
(
name__icontains
=
keyword
)
|
Q
(
comment__icontains
=
keyword
))
if
sort
:
self
.
queryset
=
self
.
queryset
.
order_by
(
sort
)
return
self
.
queryset
#
def get_queryset(self):
#
self.queryset = super(IDCListView, self).get_queryset()
#
self.keyword = keyword = self.request.GET.get('keyword', '')
#
self.sort = sort = self.request.GET.get('sort', '-date_created')
#
#
if keyword:
#
self.queryset = self.queryset.filter(Q(name__icontains=keyword) |
#
Q(comment__icontains=keyword))
#
#
if sort:
#
self.queryset = self.queryset.order_by(sort)
#
return self.queryset
class
IDCCreateView
(
AdminUserRequiredMixin
,
CreateView
):
...
...
@@ -414,7 +414,15 @@ class IDCUpdateView(AdminUserRequiredMixin, UpdateView):
class
IDCDetailView
(
AdminUserRequiredMixin
,
DetailView
):
pass
model
=
IDC
template_name
=
'assets/idc_detail.html'
context_object_name
=
'idc'
class
IDCAssetsView
(
AdminUserRequiredMixin
,
DetailView
):
model
=
IDC
template_name
=
'assets/idc_assets.html'
context_object_name
=
'idc'
class
IDCDeleteView
(
AdminUserRequiredMixin
,
DeleteView
):
...
...
apps/
common/templates/common
/flash_message_standalone.html
→
apps/
templates
/flash_message_standalone.html
View file @
968b1b4c
File moved
apps/users/models.py
View file @
968b1b4c
...
...
@@ -234,7 +234,7 @@ class User(AbstractUser):
user
.
groups
.
add
(
UserGroup
.
initial
())
def
delete
(
self
):
if
self
.
pk
==
1
:
if
self
.
pk
==
1
or
self
.
username
==
'admin'
:
return
return
super
(
User
,
self
)
.
delete
()
...
...
apps/users/templates/users/user_list.html
View file @
968b1b4c
...
...
@@ -79,7 +79,7 @@ $(document).ready(function(){
{
targets
:
7
,
createdCell
:
function
(
td
,
cellData
,
rowData
)
{
var
update_btn
=
'<a href="{% url "users:user-update" pk=99991937 %}" class="btn btn-xs btn-info">{% trans "Update" %}</a>'
.
replace
(
'99991937'
,
cellData
);
var
del_btn
=
'<a class="btn btn-xs btn-danger m-l-xs btn_user_delete" data-uid="99991937">{% trans "Delete" %}</a>'
.
replace
(
'99991937'
,
cellData
);
if
(
rowData
.
id
===
1
)
{
if
(
rowData
.
id
===
1
||
rowData
.
username
==
"admin"
)
{
$
(
td
).
html
(
update_btn
)
}
else
{
$
(
td
).
html
(
update_btn
+
del_btn
)
...
...
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