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
7b57d24d
Commit
7b57d24d
authored
May 28, 2018
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 优化代码
parent
ffabef00
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
16 additions
and
14 deletions
+16
-14
asset.py
apps/assets/api/asset.py
+11
-3
asset.py
apps/assets/models/asset.py
+3
-1
node.py
apps/assets/models/node.py
+0
-8
node.py
apps/assets/serializers/node.py
+1
-1
_asset_list_modal.html
apps/assets/templates/assets/_asset_list_modal.html
+1
-1
No files found.
apps/assets/api/asset.py
View file @
7b57d24d
...
@@ -48,14 +48,22 @@ class AssetViewSet(IDInFilterMixin, LabelFilter, BulkModelViewSet):
...
@@ -48,14 +48,22 @@ class AssetViewSet(IDInFilterMixin, LabelFilter, BulkModelViewSet):
if
admin_user_id
:
if
admin_user_id
:
admin_user
=
get_object_or_404
(
AdminUser
,
id
=
admin_user_id
)
admin_user
=
get_object_or_404
(
AdminUser
,
id
=
admin_user_id
)
queryset
=
queryset
.
filter
(
admin_user
=
admin_user
)
queryset
=
queryset
.
filter
(
admin_user
=
admin_user
)
if
node_id
:
if
node_id
and
show_current_asset
:
queryset
=
queryset
.
filter
(
Q
(
nodes
=
node_id
)
|
Q
(
nodes__isnull
=
True
)
)
.
distinct
()
if
node_id
and
not
show_current_asset
:
node
=
get_object_or_404
(
Node
,
id
=
node_id
)
node
=
get_object_or_404
(
Node
,
id
=
node_id
)
if
not
node
.
is_root
():
if
not
node
.
is_root
():
queryset
=
queryset
.
filter
(
Q
(
nodes__key__regex
=
'^{}(:[0-9]+)*$'
.
format
(
node
.
key
))
|
Q
(
nodes__isnull
=
True
),
)
.
distinct
()
else
:
queryset
=
queryset
.
filter
(
queryset
=
queryset
.
filter
(
nodes__key__regex
=
'^{}(:[0-9]+)*$'
.
format
(
node
.
key
),
nodes__key__regex
=
'^{}(:[0-9]+)*$'
.
format
(
node
.
key
),
)
.
distinct
()
)
.
distinct
()
if
show_current_asset
and
node_id
:
queryset
=
queryset
.
filter
(
nodes
=
node_id
)
.
distinct
()
return
queryset
return
queryset
...
...
apps/assets/models/asset.py
View file @
7b57d24d
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
import
uuid
import
uuid
import
logging
import
logging
import
random
from
django.db
import
models
from
django.db
import
models
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.utils.translation
import
ugettext_lazy
as
_
...
@@ -191,7 +192,8 @@ class Asset(models.Model):
...
@@ -191,7 +192,8 @@ class Asset(models.Model):
seed
()
seed
()
for
i
in
range
(
count
):
for
i
in
range
(
count
):
asset
=
cls
(
ip
=
'
%
s.
%
s.
%
s.
%
s'
%
(
i
,
i
,
i
,
i
),
ip
=
[
str
(
i
)
for
i
in
random
.
sample
(
range
(
255
),
4
)]
asset
=
cls
(
ip
=
'.'
.
join
(
ip
),
hostname
=
forgery_py
.
internet
.
user_name
(
True
),
hostname
=
forgery_py
.
internet
.
user_name
(
True
),
admin_user
=
choice
(
AdminUser
.
objects
.
all
()),
admin_user
=
choice
(
AdminUser
.
objects
.
all
()),
port
=
22
,
port
=
22
,
...
...
apps/assets/models/node.py
View file @
7b57d24d
...
@@ -108,14 +108,6 @@ class Node(models.Model):
...
@@ -108,14 +108,6 @@ class Node(models.Model):
assets
=
Asset
.
objects
.
filter
(
nodes__in
=
nodes
)
.
distinct
()
assets
=
Asset
.
objects
.
filter
(
nodes__in
=
nodes
)
.
distinct
()
return
assets
return
assets
def
get_current_assets
(
self
):
from
.asset
import
Asset
assets
=
Asset
.
objects
.
filter
(
nodes
=
self
)
.
distinct
()
return
assets
def
has_assets
(
self
):
return
self
.
get_all_assets
()
def
get_all_valid_assets
(
self
):
def
get_all_valid_assets
(
self
):
return
self
.
get_all_assets
()
.
valid
()
return
self
.
get_all_assets
()
.
valid
()
...
...
apps/assets/serializers/node.py
View file @
7b57d24d
...
@@ -80,7 +80,7 @@ class NodeSerializer(serializers.ModelSerializer):
...
@@ -80,7 +80,7 @@ class NodeSerializer(serializers.ModelSerializer):
class
NodeCurrentSerializer
(
NodeSerializer
):
class
NodeCurrentSerializer
(
NodeSerializer
):
@staticmethod
@staticmethod
def
get_assets_amount
(
obj
):
def
get_assets_amount
(
obj
):
return
obj
.
get_
current_
assets
()
.
count
()
return
obj
.
get_assets
()
.
count
()
class
NodeAssetsSerializer
(
serializers
.
ModelSerializer
):
class
NodeAssetsSerializer
(
serializers
.
ModelSerializer
):
...
...
apps/assets/templates/assets/_asset_list_modal.html
View file @
7b57d24d
...
@@ -59,7 +59,7 @@ var zTree2, asset_table2 = 0;
...
@@ -59,7 +59,7 @@ var zTree2, asset_table2 = 0;
function
initTable2
()
{
function
initTable2
()
{
var
options
=
{
var
options
=
{
ele
:
$
(
'#asset_list_modal_table'
),
ele
:
$
(
'#asset_list_modal_table'
),
ajax_url
:
'{% url "api-assets:asset-list" %}'
,
ajax_url
:
'{% url "api-assets:asset-list" %}
?show_current_asset=1
'
,
columns
:
[
columns
:
[
{
data
:
"id"
},
{
data
:
"hostname"
},
{
data
:
"ip"
}
{
data
:
"id"
},
{
data
:
"hostname"
},
{
data
:
"ip"
}
],
],
...
...
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