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
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
17 additions
and
15 deletions
+17
-15
asset.py
apps/assets/api/asset.py
+12
-4
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
...
...
@@ -13,7 +13,7 @@ from common.mixins import IDInFilterMixin
from
common.utils
import
get_logger
from
..hands
import
IsSuperUser
,
IsValidUser
,
IsSuperUserOrAppUser
,
\
NodePermissionUtil
from
..models
import
Asset
,
SystemUser
,
AdminUser
,
Node
from
..models
import
Asset
,
SystemUser
,
AdminUser
,
Node
from
..
import
serializers
from
..tasks
import
update_asset_hardware_info_manual
,
\
test_asset_connectability_manual
...
...
@@ -48,14 +48,22 @@ class AssetViewSet(IDInFilterMixin, LabelFilter, BulkModelViewSet):
if
admin_user_id
:
admin_user
=
get_object_or_404
(
AdminUser
,
id
=
admin_user_id
)
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
)
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
(
nodes__key__regex
=
'^{}(:[0-9]+)*$'
.
format
(
node
.
key
),
)
.
distinct
()
if
show_current_asset
and
node_id
:
queryset
=
queryset
.
filter
(
nodes
=
node_id
)
.
distinct
()
return
queryset
...
...
apps/assets/models/asset.py
View file @
7b57d24d
...
...
@@ -4,6 +4,7 @@
import
uuid
import
logging
import
random
from
django.db
import
models
from
django.utils.translation
import
ugettext_lazy
as
_
...
...
@@ -191,7 +192,8 @@ class Asset(models.Model):
seed
()
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
),
admin_user
=
choice
(
AdminUser
.
objects
.
all
()),
port
=
22
,
...
...
apps/assets/models/node.py
View file @
7b57d24d
...
...
@@ -108,14 +108,6 @@ class Node(models.Model):
assets
=
Asset
.
objects
.
filter
(
nodes__in
=
nodes
)
.
distinct
()
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
):
return
self
.
get_all_assets
()
.
valid
()
...
...
apps/assets/serializers/node.py
View file @
7b57d24d
...
...
@@ -80,7 +80,7 @@ class NodeSerializer(serializers.ModelSerializer):
class
NodeCurrentSerializer
(
NodeSerializer
):
@staticmethod
def
get_assets_amount
(
obj
):
return
obj
.
get_
current_
assets
()
.
count
()
return
obj
.
get_assets
()
.
count
()
class
NodeAssetsSerializer
(
serializers
.
ModelSerializer
):
...
...
apps/assets/templates/assets/_asset_list_modal.html
View file @
7b57d24d
...
...
@@ -59,7 +59,7 @@ var zTree2, asset_table2 = 0;
function
initTable2
()
{
var
options
=
{
ele
:
$
(
'#asset_list_modal_table'
),
ajax_url
:
'{% url "api-assets:asset-list" %}'
,
ajax_url
:
'{% url "api-assets:asset-list" %}
?show_current_asset=1
'
,
columns
:
[
{
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