Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
gjl2004yn
jumpserver
提交
4d1da568
J
jumpserver
项目概览
gjl2004yn
/
jumpserver
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jumpserver
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4d1da568
编写于
7月 16, 2018
作者:
baltery
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Update] 修改asset api
上级
3e17e942
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
29 addition
and
21 deletion
+29
-21
apps/assets/api/node.py
apps/assets/api/node.py
+2
-4
apps/assets/models/node.py
apps/assets/models/node.py
+8
-4
apps/assets/templates/assets/asset_list.html
apps/assets/templates/assets/asset_list.html
+2
-0
apps/assets/views/asset.py
apps/assets/views/asset.py
+1
-1
apps/orgs/mixins.py
apps/orgs/mixins.py
+8
-4
apps/orgs/utils.py
apps/orgs/utils.py
+6
-7
apps/users/models/group.py
apps/users/models/group.py
+2
-1
未找到文件。
apps/assets/api/node.py
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录