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
7e3cf908
Commit
7e3cf908
authored
Jul 27, 2018
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 修改get_all_assets
parent
a48fb9de
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
17 deletions
+23
-17
node.py
apps/assets/models/node.py
+23
-17
No files found.
apps/assets/models/node.py
View file @
7e3cf908
...
...
@@ -110,16 +110,22 @@ class Node(OrgModelMixin):
def
get_all_assets
(
self
):
from
.asset
import
Asset
if
self
.
is_root
():
assets
=
Asset
.
objects
.
all
()
pattern
=
r'^{0}$|^{0}:'
.
format
(
self
.
key
)
args
=
[]
kwargs
=
{}
if
self
.
is_default_node
():
args
.
append
(
Q
(
nodes__key__regex
=
pattern
)
|
Q
(
nodes__key
=
None
))
else
:
pattern
=
r'^{0}$|^{0}:'
.
format
(
self
.
key
)
assets
=
Asset
.
objects
.
filter
(
nodes__key__regex
=
pattern
)
kwargs
[
'nodes__key__regex'
]
=
pattern
assets
=
Asset
.
objects
.
filter
(
*
args
,
**
kwargs
)
return
assets
def
get_all_valid_assets
(
self
):
return
self
.
get_all_assets
()
.
valid
()
def
is_default_node
(
self
):
return
self
.
is_root
()
and
self
.
key
==
'0'
def
is_root
(
self
):
if
self
.
key
.
isdigit
():
return
True
...
...
@@ -129,7 +135,7 @@ class Node(OrgModelMixin):
@property
def
parent
(
self
):
if
self
.
is_root
():
return
self
.
__class__
.
root
()
return
self
parent_key
=
":"
.
join
(
self
.
key
.
split
(
":"
)[:
-
1
])
try
:
parent
=
self
.
__class__
.
objects
.
get
(
key
=
parent_key
)
...
...
@@ -139,17 +145,17 @@ class Node(OrgModelMixin):
@parent.setter
def
parent
(
self
,
parent
):
if
self
.
is_node
:
children
=
self
.
get_all_children
()
old_key
=
self
.
key
with
transaction
.
atomic
():
self
.
key
=
parent
.
get_next_child_key
()
for
child
in
children
:
child
.
key
=
child
.
key
.
replace
(
old_key
,
self
.
key
,
1
)
child
.
save
()
self
.
save
(
)
else
:
self
.
key
=
parent
.
key
+
':fake'
if
not
self
.
is_node
:
self
.
key
=
parent
.
key
+
':fake'
return
children
=
self
.
get_all_children
()
old_key
=
self
.
key
with
transaction
.
atomic
()
:
self
.
key
=
parent
.
get_next_child_key
(
)
for
child
in
children
:
child
.
key
=
child
.
key
.
replace
(
old_key
,
self
.
key
,
1
)
child
.
save
()
self
.
save
()
def
get_ancestor
(
self
,
with_self
=
False
):
if
self
.
is_root
():
...
...
@@ -175,7 +181,7 @@ class Node(OrgModelMixin):
set_current_org
(
Organization
.
root
())
org_nodes_roots
=
cls
.
objects
.
filter
(
key__regex
=
r'^[0-9]+$'
)
org_nodes_roots_keys
=
org_nodes_roots
.
values_list
(
'key'
,
flat
=
True
)
max_value
=
max
([
int
(
k
)
for
k
in
org_nodes_roots_keys
])
if
org_nodes_roots_keys
else
0
max_value
=
max
([
int
(
k
)
for
k
in
org_nodes_roots_keys
])
if
org_nodes_roots_keys
else
-
1
set_current_org
(
_current_org
)
root
=
cls
.
objects
.
create
(
key
=
str
(
max_value
+
1
),
value
=
_current_org
.
name
)
return
root
...
...
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