Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
gjl2004yn
jumpserver
提交
460fa8e8
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,发现更多精彩内容 >>
提交
460fa8e8
编写于
1月 30, 2018
作者:
baltery
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Feature] tree
上级
9e09a962
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
60 addition
and
0 deletion
+60
-0
apps/assets/models/__init__.py
apps/assets/models/__init__.py
+1
-0
apps/assets/models/asset.py
apps/assets/models/asset.py
+1
-0
apps/assets/models/tree.py
apps/assets/models/tree.py
+58
-0
未找到文件。
apps/assets/models/__init__.py
浏览文件 @
460fa8e8
...
...
@@ -5,5 +5,6 @@ from .user import AdminUser, SystemUser
from
.label
import
Label
from
.cluster
import
*
from
.group
import
*
from
.tree
import
*
from
.asset
import
*
from
.utils
import
*
apps/assets/models/asset.py
浏览文件 @
460fa8e8
...
...
@@ -36,6 +36,7 @@ class Asset(models.Model):
port
=
models
.
IntegerField
(
default
=
22
,
verbose_name
=
_
(
'Port'
))
groups
=
models
.
ManyToManyField
(
AssetGroup
,
blank
=
True
,
related_name
=
'assets'
,
verbose_name
=
_
(
'Asset groups'
))
cluster
=
models
.
ForeignKey
(
Cluster
,
related_name
=
'assets'
,
default
=
default_cluster
,
on_delete
=
models
.
SET_DEFAULT
,
verbose_name
=
_
(
'Cluster'
))
nodes
=
models
.
ManyToManyField
(
'assets.Node'
,
blank
=
True
,
related_name
=
'assets'
,
verbose_name
=
_
(
"Nodes"
))
is_active
=
models
.
BooleanField
(
default
=
True
,
verbose_name
=
_
(
'Is active'
))
# Auth
...
...
apps/assets/models/tree.py
0 → 100644
浏览文件 @
460fa8e8
# -*- coding: utf-8 -*-
#
from
django.db
import
models
from
django.utils.translation
import
ugettext_lazy
as
_
__all__
=
[
'Node'
]
class
Node
(
models
.
Model
):
id
=
models
.
CharField
(
primary_key
=
True
,
max_length
=
64
)
# '1:1:1:1'
name
=
models
.
CharField
(
max_length
=
128
,
verbose_name
=
_
(
"Name"
))
child_mark
=
models
.
IntegerField
(
default
=
0
)
date_create
=
models
.
DateTimeField
(
auto_now_add
=
True
)
def
__str__
(
self
):
return
self
.
name
@
property
def
level
(
self
):
return
len
(
self
.
id
.
split
(
':'
))
def
get_next_child_id
(
self
):
mark
=
self
.
child_mark
self
.
child_mark
+=
1
self
.
save
()
return
"{}:{}"
.
format
(
self
.
id
,
mark
)
def
create_child
(
self
,
name
):
child_id
=
self
.
get_next_child_id
()
child
=
self
.
__class__
.
objects
.
create
(
id
=
child_id
,
name
=
name
)
return
child
def
get_children
(
self
):
return
self
.
__class__
.
objects
.
filter
(
id__regex
=
r
'{}:[0-9]+$'
.
format
(
self
.
id
))
def
get_all_children
(
self
):
return
self
.
__class__
.
objects
.
filter
(
id__startswith
=
'{}:'
.
format
(
self
.
id
))
def
get_assets
(
self
):
from
.asset
import
Asset
children
=
self
.
get_children
()
assets
=
Asset
.
objects
.
filter
(
nodes__in
=
children
)
return
assets
def
get_all_assets
(
self
):
from
.asset
import
Asset
children
=
self
.
get_all_children
()
assets
=
Asset
.
objects
.
filter
(
nodes__in
=
children
)
return
assets
@
classmethod
def
root
(
cls
):
obj
,
created
=
cls
.
objects
.
get_or_create
(
id
=
'0'
,
defaults
=
{
"id"
:
'0'
,
'name'
:
"ROOT"
}
)
return
obj
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录