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
cd2b88ca
Commit
cd2b88ca
authored
Aug 14, 2018
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 修改节点full value
parent
1877511a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
6 deletions
+35
-6
node.py
apps/assets/models/node.py
+29
-6
signals_handler.py
apps/assets/signals_handler.py
+6
-0
No files found.
apps/assets/models/node.py
View file @
cd2b88ca
...
...
@@ -5,9 +5,10 @@ import uuid
from
django.db
import
models
,
transaction
from
django.db.models
import
Q
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.core.cache
import
cache
from
orgs.mixins
import
OrgModelMixin
from
orgs.utils
import
current_org
,
set_current_org
,
get_current_org
from
orgs.utils
import
set_current_org
,
get_current_org
from
orgs.models
import
Organization
__all__
=
[
'Node'
]
...
...
@@ -21,10 +22,10 @@ class Node(OrgModelMixin):
date_create
=
models
.
DateTimeField
(
auto_now_add
=
True
)
is_node
=
True
_full_value_cache_key_prefix
=
'_NODE_VALUE_{}'
def
__str__
(
self
):
return
self
.
value
# return self.full_value
return
self
.
full_value
def
__eq__
(
self
,
other
):
return
self
.
key
==
other
.
key
...
...
@@ -47,10 +48,29 @@ class Node(OrgModelMixin):
@property
def
full_value
(
self
):
ancestor
=
[
a
.
value
for
a
in
self
.
get_ancestor
(
with_self
=
True
)]
key
=
self
.
_full_value_cache_key_prefix
.
format
(
self
.
key
)
cached
=
cache
.
get
(
key
)
if
cached
:
return
cached
value
=
self
.
get_full_value
()
self
.
cache_full_value
(
value
)
return
value
def
get_full_value
(
self
):
# ancestor = [a.value for a in self.get_ancestor(with_self=True)]
if
self
.
is_root
():
return
self
.
value
return
' / '
.
join
(
ancestor
)
parent_full_value
=
self
.
parent
.
full_value
value
=
parent_full_value
+
' / '
+
self
.
value
return
value
def
cache_full_value
(
self
,
value
):
key
=
self
.
_full_value_cache_key_prefix
.
format
(
self
.
key
)
cache
.
set
(
key
,
value
,
3600
)
def
expire_full_value
(
self
):
key
=
self
.
_full_value_cache_key_prefix
.
format
(
self
.
key
)
cache
.
delete_pattern
(
key
+
'*'
)
@property
def
level
(
self
):
...
...
@@ -204,6 +224,10 @@ class Node(OrgModelMixin):
defaults
=
{
'value'
:
'Default'
}
return
cls
.
objects
.
get_or_create
(
defaults
=
defaults
,
key
=
'0'
)
@classmethod
def
get_tree_name_ref
(
cls
):
pass
@classmethod
def
generate_fake
(
cls
,
count
=
100
):
import
random
...
...
@@ -212,4 +236,3 @@ class Node(OrgModelMixin):
node
.
create_child
(
'Node {}'
.
format
(
i
))
apps/assets/signals_handler.py
View file @
cd2b88ca
...
...
@@ -86,3 +86,9 @@ def on_node_assets_changed(sender, instance=None, **kwargs):
system_users
=
SystemUser
.
objects
.
filter
(
nodes
=
instance
)
for
system_user
in
system_users
:
system_user
.
assets
.
add
(
*
tuple
(
assets
))
@receiver
(
post_save
,
sender
=
Node
)
def
on_node_update_or_created
(
sender
,
instance
=
None
,
created
=
False
,
**
kwargs
):
if
instance
and
not
created
:
instance
.
expire_full_value
()
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