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
4d1da568
Commit
4d1da568
authored
Jul 16, 2018
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 修改asset api
parent
3e17e942
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
29 additions
and
21 deletions
+29
-21
node.py
apps/assets/api/node.py
+2
-4
node.py
apps/assets/models/node.py
+8
-4
asset_list.html
apps/assets/templates/assets/asset_list.html
+2
-0
asset.py
apps/assets/views/asset.py
+1
-1
mixins.py
apps/orgs/mixins.py
+8
-4
utils.py
apps/orgs/utils.py
+6
-7
group.py
apps/users/models/group.py
+2
-1
No files found.
apps/assets/api/node.py
View file @
4d1da568
...
...
@@ -30,10 +30,8 @@ from .. import serializers
logger
=
get_logger
(
__file__
)
__all__
=
[
'NodeViewSet'
,
'NodeChildrenApi'
,
'NodeAssetsApi'
,
'NodeAddAssetsApi'
,
'NodeRemoveAssetsApi'
,
'NodeReplaceAssetsApi'
,
'NodeViewSet'
,
'NodeChildrenApi'
,
'NodeAssetsApi'
,
'NodeAddAssetsApi'
,
'NodeRemoveAssetsApi'
,
'NodeReplaceAssetsApi'
,
'NodeAddChildrenApi'
,
'RefreshNodeHardwareInfoApi'
,
'TestNodeConnectiveApi'
]
...
...
apps/assets/models/node.py
View file @
4d1da568
...
...
@@ -64,6 +64,9 @@ class Node(OrgModelMixin):
def
create_child
(
self
,
value
):
with
transaction
.
atomic
():
child_key
=
self
.
get_next_child_key
()
print
(
"Create child"
)
print
(
self
.
key
)
print
(
child_key
)
child
=
self
.
__class__
.
objects
.
create
(
key
=
child_key
,
value
=
value
)
return
child
...
...
@@ -120,15 +123,16 @@ class Node(OrgModelMixin):
return
self
.
get_all_assets
()
.
valid
()
def
is_root
(
self
):
root
=
self
.
__class__
.
root
()
if
self
==
root
:
print
(
type
(
self
.
key
))
print
(
self
.
key
)
if
self
.
key
.
isdigit
():
return
True
else
:
return
False
@property
def
parent
(
self
):
if
self
.
key
==
"0"
or
not
self
.
key
.
startswith
(
"0"
):
if
self
.
is_root
(
):
return
self
.
__class__
.
root
()
parent_key
=
":"
.
join
(
self
.
key
.
split
(
":"
)[:
-
1
])
try
:
...
...
@@ -155,7 +159,7 @@ class Node(OrgModelMixin):
if
self
.
is_root
():
root
=
self
.
__class__
.
root
()
return
[
root
]
print
(
self
.
key
)
_key
=
self
.
key
.
split
(
':'
)
if
not
with_self
:
_key
.
pop
()
...
...
apps/assets/templates/assets/asset_list.html
View file @
4d1da568
...
...
@@ -411,6 +411,8 @@ function initTree() {
zNodes
=
data
;
$
.
fn
.
zTree
.
init
(
$
(
"#assetTree"
),
setting
,
zNodes
);
zTree
=
$
.
fn
.
zTree
.
getZTreeObj
(
"assetTree"
);
var
root
=
zTree
.
getNodes
()[
0
];
zTree
.
expandNode
(
root
);
rMenu
=
$
(
"#rMenu"
);
selectQueryNode
();
});
...
...
apps/assets/views/asset.py
View file @
4d1da568
...
...
@@ -44,7 +44,7 @@ class AssetListView(AdminUserRequiredMixin, TemplateView):
template_name
=
'assets/asset_list.html'
def
get_context_data
(
self
,
**
kwargs
):
Node
.
root
(
)
print
(
Node
.
root
()
.
name
)
context
=
{
'app'
:
_
(
'Assets'
),
'action'
:
_
(
'Asset list'
),
...
...
apps/orgs/mixins.py
View file @
4d1da568
...
...
@@ -7,7 +7,7 @@ from django.contrib.auth import get_user_model
from
django.forms
import
ModelForm
from
common.utils
import
get_logger
from
.utils
import
get_current_org
,
get_model_by_db_table
,
set_current_org
from
.utils
import
get_current_org
,
set_current_org
logger
=
get_logger
(
__file__
)
...
...
@@ -22,23 +22,27 @@ class OrgManager(models.Manager):
current_org
=
get_current_org
()
kwargs
=
{}
print
(
">>>>>>>>>> Get query set"
)
if
not
current_org
:
kwargs
[
'id'
]
=
None
elif
current_org
.
is_real
():
kwargs
[
'org'
]
=
current_org
elif
current_org
.
is_default
():
kwargs
[
'org'
]
=
None
queryset
=
super
()
.
get_queryset
()
.
filter
(
**
kwargs
)
queryset
=
super
(
OrgManager
,
self
)
.
get_queryset
()
queryset
=
queryset
.
filter
(
**
kwargs
)
# print(kwargs)
print
(
queryset
.
query
)
return
queryset
def
all
(
self
):
current_org
=
get_current_org
()
if
not
current_org
:
msg
=
'You
should
`objects.set_current_org(org).all()` then run it'
msg
=
'You
can
`objects.set_current_org(org).all()` then run it'
warnings
.
warn
(
msg
)
return
self
else
:
return
super
()
.
all
()
return
super
(
OrgManager
,
self
)
.
all
()
def
set_current_org
(
self
,
org
):
set_current_org
(
org
)
...
...
apps/orgs/utils.py
View file @
4d1da568
...
...
@@ -35,10 +35,9 @@ def set_current_org(org):
setattr
(
_thread_locals
,
'current_org'
,
org
)
def
get_model_by_db_table
(
db_table
):
for
model
in
apps
.
get_models
():
if
model
.
_meta
.
db_table
==
db_table
:
return
model
else
:
# here you can do fallback logic if no model with db_table found
raise
ValueError
(
'No model found with db_table {}!'
.
format
(
db_table
))
def
set_to_default_org
():
set_current_org
(
Organization
.
default
())
def
set_to_root_org
():
set_current_org
(
Organization
.
root
())
apps/users/models/group.py
View file @
4d1da568
...
...
@@ -11,7 +11,7 @@ __all__ = ['UserGroup']
class
UserGroup
(
OrgModelMixin
):
id
=
models
.
UUIDField
(
default
=
uuid
.
uuid4
,
primary_key
=
True
)
name
=
models
.
CharField
(
max_length
=
128
,
unique
=
True
,
verbose_name
=
_
(
'Name'
))
name
=
models
.
CharField
(
max_length
=
128
,
verbose_name
=
_
(
'Name'
))
comment
=
models
.
TextField
(
blank
=
True
,
verbose_name
=
_
(
'Comment'
))
date_created
=
models
.
DateTimeField
(
auto_now_add
=
True
,
null
=
True
,
verbose_name
=
_
(
'Date created'
))
...
...
@@ -22,6 +22,7 @@ class UserGroup(OrgModelMixin):
class
Meta
:
ordering
=
[
'name'
]
unique_together
=
[
'org'
,
'name'
]
verbose_name
=
_
(
"User group"
)
@classmethod
...
...
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