Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
gjl2004yn
jumpserver
提交
409fac3e
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,发现更多精彩内容 >>
提交
409fac3e
编写于
9月 08, 2016
作者:
baltery
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'admin-user'
上级
62cac20b
239dd056
变更
12
展开全部
隐藏空白更改
内联
并排
Showing
12 changed file
with
444 addition
and
60 deletion
+444
-60
apps/assets/forms.py
apps/assets/forms.py
+53
-2
apps/assets/migrations/0001_initial.py
apps/assets/migrations/0001_initial.py
+10
-10
apps/assets/models.py
apps/assets/models.py
+12
-11
apps/assets/templates/assets/admin_user_create_update.html
apps/assets/templates/assets/admin_user_create_update.html
+64
-0
apps/assets/templates/assets/admin_user_detail.html
apps/assets/templates/assets/admin_user_detail.html
+220
-0
apps/assets/templates/assets/admin_user_list.html
apps/assets/templates/assets/admin_user_list.html
+1
-1
apps/assets/templates/assets/asset_group_detail.html
apps/assets/templates/assets/asset_group_detail.html
+19
-19
apps/assets/views.py
apps/assets/views.py
+61
-12
apps/fixtures/fake.json
apps/fixtures/fake.json
+1
-1
apps/users/templates/users/user_detail.html
apps/users/templates/users/user_detail.html
+2
-2
apps/users/urls.py
apps/users/urls.py
+0
-1
apps/users/views.py
apps/users/views.py
+1
-1
未找到文件。
apps/assets/forms.py
浏览文件 @
409fac3e
# coding:utf-8
from
django
import
forms
from
.models
import
IDC
,
Asset
,
AssetGroup
from
.models
import
IDC
,
Asset
,
AssetGroup
,
AdminUser
,
SystemUser
from
django.utils.translation
import
gettext_lazy
as
_
...
...
@@ -11,7 +11,7 @@ class AssetForm(forms.ModelForm):
fields
=
[
"ip"
,
"other_ip"
,
"remote_card_ip"
,
"hostname"
,
"port"
,
"groups"
,
"username"
,
"password"
,
"idc"
,
"mac_addr"
,
"brand"
,
"cpu"
,
"memory"
,
"disk"
,
"os"
,
"cabinet_no"
,
"cabinet_pos"
,
"idc"
,
"mac_addr
ess
"
,
"brand"
,
"cpu"
,
"memory"
,
"disk"
,
"os"
,
"cabinet_no"
,
"cabinet_pos"
,
"number"
,
"status"
,
"type"
,
"env"
,
"sn"
,
"is_active"
,
"comment"
]
...
...
@@ -78,3 +78,54 @@ class IDCForm(forms.ModelForm):
'network'
:
forms
.
Textarea
(
attrs
=
{
'placeholder'
:
'192.168.1.0/24
\n
192.168.2.0/24'
})
}
class
AdminUserForm
(
forms
.
ModelForm
):
assets
=
forms
.
ModelMultipleChoiceField
(
queryset
=
Asset
.
objects
.
all
(),
label
=
_
(
'Asset'
),
required
=
False
,
widget
=
forms
.
SelectMultiple
(
attrs
=
{
'class'
:
'select2'
,
'data-placeholder'
:
_
(
'Select assets'
)})
)
password
=
forms
.
CharField
(
widget
=
forms
.
PasswordInput
,
max_length
=
100
,
min_length
=
8
,
strip
=
True
,
help_text
=
_
(
'If also set private key, use that first'
),
required
=
False
)
private_key_file
=
forms
.
FileField
(
required
=
False
)
def
__init__
(
self
,
*
args
,
**
kwargs
):
if
kwargs
.
get
(
'instance'
):
initial
=
kwargs
.
get
(
'initial'
,
{})
initial
[
'assets'
]
=
kwargs
[
'instance'
].
assets
.
all
()
super
(
AdminUserForm
,
self
).
__init__
(
*
args
,
**
kwargs
)
def
_save_m2m
(
self
):
super
(
AdminUserForm
,
self
).
_save_m2m
()
assets
=
self
.
cleaned_data
[
'assets'
]
self
.
instance
.
assets
.
clear
()
self
.
instance
.
assets
.
add
(
*
tuple
(
assets
))
def
save
(
self
,
commit
=
True
):
admin_user
=
super
(
AdminUserForm
,
self
).
save
(
commit
=
commit
)
password
=
self
.
cleaned_data
[
'password'
]
private_key_file
=
self
.
cleaned_data
[
'private_key_file'
]
if
password
:
admin_user
.
password
=
password
print
(
password
)
if
private_key_file
:
print
(
private_key_file
)
admin_user
.
private_key
=
private_key_file
.
read
()
admin_user
.
save
()
return
self
.
instance
class
Meta
:
model
=
AdminUser
fields
=
[
'name'
,
'username'
,
'password'
,
'private_key_file'
,
'as_default'
,
'comment'
]
widgets
=
{
'name'
:
forms
.
TextInput
(
attrs
=
{
'placeholder'
:
_
(
'Name'
)}),
'username'
:
forms
.
TextInput
(
attrs
=
{
'placeholder'
:
_
(
'Username'
)}),
}
help_texts
=
{
'name'
:
'* required'
,
'username'
:
'* required'
,
}
apps/assets/migrations/0001_initial.py
浏览文件 @
409fac3e
# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2016-09-0
7 15:11
# Generated by Django 1.10 on 2016-09-0
8 03:02
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
...
...
@@ -18,15 +18,15 @@ class Migration(migrations.Migration):
name
=
'AdminUser'
,
fields
=
[
(
'id'
,
models
.
AutoField
(
auto_created
=
True
,
primary_key
=
True
,
serialize
=
False
,
verbose_name
=
'ID'
)),
(
'name'
,
models
.
CharField
(
blank
=
True
,
max_length
=
128
,
null
=
True
,
unique
=
True
,
verbose_name
=
'Name'
)),
(
'username'
,
models
.
CharField
(
blank
=
True
,
max_length
=
16
,
null
=
True
,
verbose_name
=
'Username'
)),
(
'password'
,
models
.
CharField
(
blank
=
True
,
max_length
=
256
,
null
=
True
,
verbose_name
=
'Password'
)),
(
'private_key'
,
models
.
CharField
(
blank
=
True
,
max_length
=
4096
,
null
=
True
,
verbose_name
=
'SSH private key'
)),
(
'is_default'
,
models
.
BooleanField
(
default
=
True
,
verbose_name
=
'As default'
)),
(
'auto_update'
,
models
.
BooleanField
(
default
=
True
,
verbose_name
=
'Auto update pass/key'
)),
(
'date_created'
,
models
.
DateTimeField
(
auto_now
=
True
,
null
=
True
)),
(
'create_by'
,
models
.
CharField
(
blank
=
True
,
max_length
=
32
,
null
=
True
,
verbose_name
=
'Created by'
)),
(
'name'
,
models
.
CharField
(
max_length
=
128
,
unique
=
True
,
verbose_name
=
'Name'
)),
(
'username'
,
models
.
CharField
(
max_length
=
16
,
verbose_name
=
'Username'
)),
(
'_password'
,
models
.
CharField
(
blank
=
True
,
max_length
=
256
,
verbose_name
=
'Password'
)),
(
'_private_key'
,
models
.
CharField
(
blank
=
True
,
max_length
=
4096
,
verbose_name
=
'SSH private key'
)),
(
'_public_key'
,
models
.
CharField
(
blank
=
True
,
max_length
=
4096
,
verbose_name
=
'SSH public key'
)),
(
'as_default'
,
models
.
BooleanField
(
default
=
False
,
verbose_name
=
'As default'
)),
(
'comment'
,
models
.
TextField
(
blank
=
True
,
verbose_name
=
'Comment'
)),
(
'date_created'
,
models
.
DateTimeField
(
auto_now
=
True
,
null
=
True
)),
(
'created_by'
,
models
.
CharField
(
max_length
=
32
,
null
=
True
,
verbose_name
=
'Created by'
)),
],
options
=
{
'db_table'
:
'admin_user'
,
...
...
@@ -142,7 +142,7 @@ class Migration(migrations.Migration):
(
'home'
,
models
.
CharField
(
blank
=
True
,
max_length
=
64
,
verbose_name
=
'Home'
)),
(
'uid'
,
models
.
IntegerField
(
blank
=
True
,
verbose_name
=
'Uid'
)),
(
'date_created'
,
models
.
DateTimeField
(
auto_now
=
True
,
null
=
True
)),
(
'create_by'
,
models
.
CharField
(
blank
=
True
,
max_length
=
32
,
verbose_name
=
'Created by'
)),
(
'create
d
_by'
,
models
.
CharField
(
blank
=
True
,
max_length
=
32
,
verbose_name
=
'Created by'
)),
(
'comment'
,
models
.
CharField
(
blank
=
True
,
max_length
=
128
,
verbose_name
=
'Comment'
)),
],
options
=
{
...
...
apps/assets/models.py
浏览文件 @
409fac3e
...
...
@@ -68,15 +68,15 @@ class AssetExtend(models.Model):
class
AdminUser
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
128
,
unique
=
True
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Name'
))
username
=
models
.
CharField
(
max_length
=
16
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Username'
))
_password
=
models
.
CharField
(
max_length
=
256
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Password'
))
_private_key
=
models
.
CharField
(
max_length
=
4096
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'SSH private key'
))
_public_key
=
models
.
CharField
(
max_length
=
4096
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'SSH public key'
))
as_default
=
models
.
BooleanField
(
default
=
Tru
e
,
verbose_name
=
_
(
'As default'
))
name
=
models
.
CharField
(
max_length
=
128
,
unique
=
True
,
verbose_name
=
_
(
'Name'
))
username
=
models
.
CharField
(
max_length
=
16
,
verbose_name
=
_
(
'Username'
))
_password
=
models
.
CharField
(
max_length
=
256
,
blank
=
True
,
verbose_name
=
_
(
'Password'
))
_private_key
=
models
.
CharField
(
max_length
=
4096
,
blank
=
True
,
verbose_name
=
_
(
'SSH private key'
))
_public_key
=
models
.
CharField
(
max_length
=
4096
,
blank
=
True
,
verbose_name
=
_
(
'SSH public key'
))
as_default
=
models
.
BooleanField
(
default
=
Fals
e
,
verbose_name
=
_
(
'As default'
))
comment
=
models
.
TextField
(
blank
=
True
,
verbose_name
=
_
(
'Comment'
))
date_created
=
models
.
DateTimeField
(
auto_now
=
True
,
null
=
True
,
blank
=
True
)
created_by
=
models
.
CharField
(
max_length
=
32
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Created by'
))
date_created
=
models
.
DateTimeField
(
auto_now
=
True
,
null
=
True
)
created_by
=
models
.
CharField
(
max_length
=
32
,
null
=
True
,
verbose_name
=
_
(
'Created by'
))
def
__unicode__
(
self
):
return
self
.
name
...
...
@@ -110,7 +110,7 @@ class AdminUser(models.Model):
@
classmethod
def
generate_fake
(
cls
,
count
=
100
):
from
random
import
seed
,
choice
from
random
import
seed
import
forgery_py
from
django.db
import
IntegrityError
...
...
@@ -204,10 +204,11 @@ class Asset(models.Model):
groups
=
models
.
ManyToManyField
(
AssetGroup
,
related_name
=
'assets'
,
verbose_name
=
_
(
'Asset groups'
))
username
=
models
.
CharField
(
max_length
=
16
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Admin user'
))
password
=
models
.
CharField
(
max_length
=
256
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
"Admin password"
))
admin_user
=
models
.
ForeignKey
(
AdminUser
,
null
=
True
,
on_delete
=
models
.
SET_NULL
,
verbose_name
=
_
(
"Admin user"
))
admin_user
=
models
.
ForeignKey
(
AdminUser
,
null
=
True
,
related_name
=
'assets'
,
on_delete
=
models
.
SET_NULL
,
verbose_name
=
_
(
"Admin user"
))
system_user
=
models
.
ManyToManyField
(
SystemUser
,
blank
=
True
,
verbose_name
=
_
(
"System User"
))
idc
=
models
.
ForeignKey
(
IDC
,
null
=
True
,
related_name
=
'assets'
,
on_delete
=
models
.
SET_NULL
,
verbose_name
=
_
(
'IDC'
))
mac_addr
=
models
.
CharField
(
max_length
=
20
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
"Mac address"
))
mac_addr
ess
=
models
.
CharField
(
max_length
=
20
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
"Mac address"
))
brand
=
models
.
CharField
(
max_length
=
64
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Brand'
))
cpu
=
models
.
CharField
(
max_length
=
64
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'CPU'
))
memory
=
models
.
CharField
(
max_length
=
128
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Memory'
))
...
...
apps/assets/templates/assets/admin_user_create_update.html
0 → 100644
浏览文件 @
409fac3e
{% extends 'base.html' %}
{% load i18n %}
{% load static %}
{% load bootstrap %}
{% block custom_head_css_js %}
<link
href=
"{% static "
css
/
plugins
/
select2
/
select2.min.css
"
%}"
rel=
"stylesheet"
>
<script
src=
"{% static "
js
/
plugins
/
select2
/
select2.full.min.js
"
%}"
></script>
{% endblock %}
{% block content %}
<div
class=
"wrapper wrapper-content animated fadeInRight"
>
<div
class=
"row"
>
<div
class=
"col-sm-12"
>
<div
class=
"ibox float-e-margins"
>
<div
class=
"ibox-title"
>
<h5>
{% trans 'Create asset group' %}
</h5>
<div
class=
"ibox-tools"
>
<a
class=
"collapse-link"
>
<i
class=
"fa fa-chevron-up"
></i>
</a>
<a
class=
"dropdown-toggle"
data-toggle=
"dropdown"
href=
"#"
>
<i
class=
"fa fa-wrench"
></i>
</a>
<a
class=
"close-link"
>
<i
class=
"fa fa-times"
></i>
</a>
</div>
</div>
<div
class=
"ibox-content"
>
<form
enctype=
"multipart/form-data"
method=
"post"
class=
"form-horizontal"
action=
""
>
{% csrf_token %}
{{ form.name|bootstrap_horizontal }}
{{ form.username|bootstrap_horizontal }}
{{ form.password|bootstrap_horizontal }}
{{ form.private_key_file|bootstrap_horizontal }}
<div
class=
"form-group"
>
<label
for=
"{{ form.as_default.id_for_label }}"
class=
"col-sm-2 control-label"
>
{% trans 'As default' %}
</label>
<div
class=
"col-sm-8"
>
{{ form.as_default}}
</div>
</div>
{{ form.assets|bootstrap_horizontal }}
{{ form.comment|bootstrap_horizontal }}
<div
class=
"form-group"
>
<div
class=
"col-sm-4 col-sm-offset-2"
>
<button
class=
"btn btn-white"
type=
"reset"
>
{% trans 'Reset' %}
</button>
<button
id=
"submit_button"
class=
"btn btn-primary"
type=
"submit"
>
{% trans 'Submit' %}
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
{% block custom_foot_js %}
<script>
$
(
document
).
ready
(
function
()
{
$
(
'
.select2
'
).
select2
();
})
</script>
{% endblock %}
\ No newline at end of file
apps/assets/templates/assets/admin_user_detail.html
0 → 100644
浏览文件 @
409fac3e
{% extends 'base.html' %}
{% load common_tags %}
{% load users_tags %}
{% load static %}
{% load i18n %}
{% block custom_head_css_js %}
<link
href=
"{% static "
css
/
plugins
/
select2
/
select2.min.css
"
%}"
rel=
"stylesheet"
>
<script
src=
"{% static "
js
/
plugins
/
select2
/
select2.full.min.js
"
%}"
></script>
{% endblock %}
{% block content %}
<div
class=
"wrapper wrapper-content animated fadeInRight"
>
<div
class=
"row"
>
<div
class=
"col-sm-12"
>
<div
class=
"ibox float-e-margins"
>
<div
class=
"panel-options"
>
<ul
class=
"nav nav-tabs"
>
<li
class=
"active"
><a
href=
""
class=
"text-center"
><i
class=
"fa fa-laptop"
></i>
{% trans 'Detail' %}
</a>
</li>
<li><a
href=
""
class=
"text-center"
><i
class=
"fa fa-bar-chart-o"
></i>
{% trans 'Associate assets' %}
</a></li>
</ul>
</div>
<div
class=
"tab-content"
>
<div
class=
"col-sm-7"
style=
"padding-left: 0;"
>
<div
class=
"ibox float-e-margins"
>
<div
class=
"ibox-title"
>
<span
class=
"label"
><b>
{{ admin_user.name }}
</b></span>
<div
class=
"ibox-tools"
>
<a
class=
"collapse-link"
>
<i
class=
"fa fa-chevron-up"
></i>
</a>
<a
class=
"dropdown-toggle"
data-toggle=
"dropdown"
href=
"#"
>
<i
class=
"fa fa-wrench"
></i>
</a>
<ul
class=
"dropdown-menu dropdown-user"
>
<li><a
href=
"#"
></a>
</li>
<li><a
href=
"#"
></a>
</li>
</ul>
<a
class=
"close-link"
>
<i
class=
"fa fa-times"
></i>
</a>
</div>
</div>
<div
class=
"ibox-content"
>
<table
class=
"table"
>
<tbody>
<tr
class=
"no-borders-tr"
>
<td>
{% trans 'Name' %}:
</td>
<td><b>
{{ admin_user.name }}
</b></td>
</tr>
<tr>
<td>
{% trans 'Username' %}:
</td>
<td><b>
{{ admin_user.username }}
</b></td>
</tr>
<tr>
<td>
{% trans 'Date created' %}:
</td>
<td><b>
{{ admin_user.date_created }}
</b></td>
</tr>
<tr>
<td>
{% trans 'Created by' %}:
</td>
<td><b>
{{ asset_group.created_by }}
</b></td>
</tr>
<tr>
<td>
{% trans 'Comment' %}:
</td>
<td><b>
{{ admin_user.comment }}
</b></td>
</tr>
</tbody>
</table>
</div>
</div>
<div
class=
"ibox float-e-margins"
>
<div
class=
"ibox-title"
>
<span
style=
"float: left"
>
{% trans 'Asset list of ' %}
<b>
{{ admin_user.name }}
</b></span>
<div
class=
"ibox-tools"
>
<a
class=
"collapse-link"
>
<i
class=
"fa fa-chevron-up"
></i>
</a>
<a
class=
"dropdown-toggle"
data-toggle=
"dropdown"
href=
"#"
>
<i
class=
"fa fa-wrench"
></i>
</a>
<ul
class=
"dropdown-menu dropdown-user"
>
<li><a
href=
"#"
></a>
</li>
<li><a
href=
"#"
></a>
</li>
</ul>
<a
class=
"close-link"
>
<i
class=
"fa fa-times"
></i>
</a>
</div>
</div>
<div
class=
"ibox-content"
>
<table
class=
"table table-hover"
>
<thead>
<tr>
<th>
{% trans 'Hostname' %}
</th>
<th>
{% trans 'IP' %}
</th>
<th>
{% trans 'Port' %}
</th>
<th>
{% trans 'Alive' %}
</th>
</tr>
</thead>
<tbody>
{% for asset in page_obj %}
<tr>
<td>
{{ asset.hostname }}
</td>
<td>
{{ asset.ip }}
</td>
<td>
{{ asset.port }}
</td>
<td>
Alive
</td>
</tr>
{% endfor %}
</tbody>
</table>
<div
class=
"row"
>
{% include '_pagination.html' %}
</div>
</div>
</div>
</div>
<div
class=
"col-sm-5"
style=
"padding-left: 0;padding-right: 0"
>
<div
class=
"panel panel-primary"
>
<div
class=
"panel-heading"
>
<i
class=
"fa fa-info-circle"
></i>
{% trans 'Quick update' %}
</div>
<div
class=
"panel-body"
>
<table
class=
"table"
>
<tbody>
<tr
class=
"no-borders-tr"
>
<td
width=
"50%"
>
{% trans 'Get install script' %}:
</td>
<td>
<span
style=
"float: right"
>
<button
type=
"button"
class=
"btn btn-primary btn-xs"
style=
"width: 54px"
>
{% trans 'Get' %}
</button>
</span>
</td>
</tr>
<tr>
<td
width=
"50%"
>
{% trans 'Retest asset connectivity' %}:
</td>
<td>
<span
style=
"float: right"
>
<button
type=
"button"
class=
"btn btn-primary btn-xs"
style=
"width: 54px"
>
{% trans 'Start' %}
</button>
</span>
</td>
</tr>
<tr>
<td
width=
"50%"
>
{% trans 'Reset private key' %}:
</td>
<td>
<span
style=
"float: right"
>
<button
type=
"button"
class=
"btn btn-primary btn-xs"
style=
"width: 54px"
>
{% trans 'Reset' %}
</button>
</span>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div
class=
"panel panel-info"
>
<div
class=
"panel-heading"
>
<i
class=
"fa fa-info-circle"
></i>
{% trans 'Replace asset admin user with this' %}
</div>
<div
class=
"panel-body"
>
<table
class=
"table"
>
<tbody>
<form>
<tr
class=
"no-borders-tr"
>
<td
colspan=
"2"
>
<select
data-placeholder=
"{% trans 'Select asset' %}"
class=
"select2"
style=
"width: 100%"
multiple=
""
tabindex=
"4"
>
{% for group in groups %}
<option
value=
"{{ group.id }}"
>
{{ group.name }}
</option>
{% endfor %}
</select>
</td>
</tr>
<tr
class=
"no-borders-tr"
>
<td
colspan=
"2"
>
<button
type=
"button"
class=
"btn btn-info btn-sm"
>
{% trans 'Replace' %}
</button>
</td>
</tr>
</form>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
{% block custom_foot_js %}
<script>
{
#
function
switch_user_status
(
obj
)
{
#
}
{
#
var
status
=
$
(
obj
).
prop
(
'
checked
'
);
#
}
{
##
}
{
#
$
.
ajax
({
#
}
{
#
url
:
"
{% url 'users:user-active-api' pk=user.id %}
"
,
#
}
{
#
type
:
"
PUT
"
,
#
}
{
#
data
:
{
#
}
{
#
'
is_active
'
:
status
#
}
{
#
},
#
}
{
#
success
:
function
(
data
,
status
)
{
#
}
{
#
console
.
log
(
data
)
#
}
{
#
},
#
}
{
#
error
:
function
()
{
#
}
{
#
console
.
log
(
'
error
'
)
#
}
{
#
}
#
}
{
#
})
#
}
{
#
}
#
}
$
(
document
).
ready
(
function
()
{
$
(
'
.select2
'
).
select2
();
});
</script>
{% endblock %}
\ No newline at end of file
apps/assets/templates/assets/admin_user_list.html
浏览文件 @
409fac3e
...
...
@@ -20,7 +20,7 @@
<tr
class=
"gradeX"
>
<td
class=
"text-center"
>
{{ admin_user.id }}
</td>
<td>
<a
href=
"{% url '
users:user-detail' pk=
user.id %}"
>
<a
href=
"{% url '
assets:admin-user-detail' pk=admin_
user.id %}"
>
{{ admin_user.name }}
</a>
</td>
...
...
apps/assets/templates/assets/asset_group_detail.html
浏览文件 @
409fac3e
...
...
@@ -69,7 +69,7 @@
<div
class=
"ibox float-e-margins"
>
<div
class=
"ibox-title"
>
<span>
{% trans 'Asset list of ' %}
<b>
{{ asset_group.name }}
</b></span>
<span
style=
"float: left"
></span
>
{% trans 'Asset list of ' %}
<b>
{{ asset_group.name }}
</b></span>
<div
class=
"ibox-tools"
>
<a
class=
"collapse-link"
>
<i
class=
"fa fa-chevron-up"
></i>
...
...
@@ -118,7 +118,7 @@
<div
class=
"col-sm-5"
style=
"padding-left: 0;padding-right: 0"
>
<div
class=
"panel panel-primary"
>
<div
class=
"panel-heading"
>
<i
class=
"fa fa-info-circle"
></i>
{% trans 'Associate
asset user(system/admin)
' %}
<i
class=
"fa fa-info-circle"
></i>
{% trans 'Associate
system user
' %}
</div>
<div
class=
"panel-body"
>
<table
class=
"table"
>
...
...
@@ -207,23 +207,23 @@
{% endblock %}
{% block custom_foot_js %}
<script>
function
switch_user_status
(
obj
)
{
var
status
=
$
(
obj
).
prop
(
'
checked
'
);
$
.
ajax
({
url
:
"
{% url 'users:user-active-api' pk=user.id %}
"
,
type
:
"
PUT
"
,
data
:
{
'
is_active
'
:
status
},
success
:
function
(
data
,
status
)
{
console
.
log
(
data
)
},
error
:
function
()
{
console
.
log
(
'
error
'
)
}
})
}
{
#
function
switch_user_status
(
obj
)
{
#
}
{
#
var
status
=
$
(
obj
).
prop
(
'
checked
'
);
#
}
{
##
}
{
#
$
.
ajax
({
#
}
{
#
url
:
"
{% url 'users:user-active-api' pk=user.id %}
"
,
#
}
{
#
type
:
"
PUT
"
,
#
}
{
#
data
:
{
#
}
{
#
'
is_active
'
:
status
#
}
{
#
},
#
}
{
#
success
:
function
(
data
,
status
)
{
#
}
{
#
console
.
log
(
data
)
#
}
{
#
},
#
}
{
#
error
:
function
()
{
#
}
{
#
console
.
log
(
'
error
'
)
#
}
{
#
}
#
}
{
#
})
#
}
{
#
}
#
}
$
(
document
).
ready
(
function
()
{
$
(
'
.select2
'
).
select2
();
})
...
...
apps/assets/views.py
浏览文件 @
409fac3e
...
...
@@ -2,19 +2,16 @@
from
__future__
import
absolute_import
,
unicode_literals
from
django.utils.translation
import
ugettext
as
_
from
django.shortcuts
import
get_object_or_404
from
django.views.generic
import
TemplateView
,
ListView
from
django.urls
import
reverse_lazy
from
django.views.generic.edit
import
CreateView
,
DeleteView
,
FormView
,
UpdateView
from
django.conf
import
settings
from
django.db.models
import
Q
from
django.views.generic
import
TemplateView
,
ListView
from
django.views.generic.edit
import
CreateView
,
DeleteView
,
FormView
,
UpdateView
from
django.urls
import
reverse_lazy
from
django.contrib.messages.views
import
SuccessMessageMixin
from
django.views.generic.detail
import
DetailView
,
SingleObjectMixin
from
.models
import
Asset
,
AssetGroup
,
IDC
,
AssetExtend
,
AdminUser
,
SystemUser
from
.forms
import
AssetForm
,
AssetGroupForm
,
IDCForm
from
.forms
import
AssetForm
,
AssetGroupForm
,
IDCForm
,
AdminUserForm
from
.hands
import
AdminUserRequiredMixin
...
...
@@ -216,7 +213,7 @@ class AdminUserListView(AdminUserRequiredMixin, ListView):
return
super
(
AdminUserListView
,
self
).
get_context_data
(
**
kwargs
)
def
get_queryset
(
self
):
# Todo: Default
group
by lose asset connection num
# Todo: Default
order
by lose asset connection num
self
.
queryset
=
super
(
AdminUserListView
,
self
).
get_queryset
()
self
.
keyword
=
keyword
=
self
.
request
.
GET
.
get
(
'keyword'
,
''
)
self
.
sort
=
sort
=
self
.
request
.
GET
.
get
(
'sort'
,
'-date_created'
)
...
...
@@ -230,17 +227,69 @@ class AdminUserListView(AdminUserRequiredMixin, ListView):
return
self
.
queryset
class
AdminUserCreateView
(
AdminUserRequiredMixin
,
CreateView
):
pass
class
AdminUserCreateView
(
AdminUserRequiredMixin
,
SuccessMessageMixin
,
CreateView
):
model
=
AdminUser
form_class
=
AdminUserForm
template_name
=
'assets/admin_user_create_update.html'
success_url
=
reverse_lazy
(
'assets:admin-user-list'
)
success_message
=
_
(
'Create admin user <a href="%s">%s</a> successfully.'
)
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
'app'
:
'assets'
,
'action'
:
'Create admin user'
}
kwargs
.
update
(
context
)
return
super
(
AdminUserCreateView
,
self
).
get_context_data
(
**
kwargs
)
def
get_success_message
(
self
,
cleaned_data
):
return
self
.
success_message
%
(
reverse_lazy
(
'assets:admin-user-detail'
,
kwargs
=
{
'pk'
:
self
.
object
.
pk
}),
self
.
object
.
name
,
)
class
AdminUserUpdateView
(
AdminUserRequiredMixin
,
UpdateView
):
pass
model
=
AdminUser
form_class
=
AdminUserForm
template_name
=
'assets/admin_user_create_update.html'
success_message
=
_
(
'Update admin user <a href="%s">%s</a> successfully.'
)
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
'app'
:
'assets'
,
'action'
:
'Update admin user'
}
kwargs
.
update
(
context
)
return
super
(
AdminUserUpdateView
,
self
).
get_context_data
(
**
kwargs
)
class
AdminUserDetailView
(
AdminUserRequiredMixin
,
DetailView
):
pass
def
get_success_url
(
self
):
success_url
=
reverse_lazy
(
'assets:admin-user-detail'
,
pk
=
self
.
object
.
pk
)
return
success_url
class
AdminUserDetailView
(
AdminUserRequiredMixin
,
SingleObjectMixin
,
ListView
):
paginate_by
=
settings
.
CONFIG
.
DISPLAY_PER_PAGE
template_name
=
'assets/admin_user_detail.html'
context_object_name
=
'admin_user'
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
self
.
object
=
self
.
get_object
(
queryset
=
AdminUser
.
objects
.
all
())
return
super
(
AdminUserDetailView
,
self
).
get
(
request
,
*
args
,
**
kwargs
)
def
get_queryset
(
self
):
return
self
.
object
.
assets
.
all
()
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
'app'
:
'assets'
,
'action'
:
'Admin user detail'
}
kwargs
.
update
(
context
)
return
super
(
AdminUserDetailView
,
self
).
get_context_data
(
**
kwargs
)
class
AdminUserDeleteView
(
AdminUserRequiredMixin
,
DeleteView
):
pass
model
=
AdminUser
template_name
=
'assets/delete_confirm.html'
success_url
=
'assets:admin-user-list'
apps/fixtures/fake.json
浏览文件 @
409fac3e
此差异已折叠。
点击以展开。
apps/users/templates/users/user_detail.html
浏览文件 @
409fac3e
...
...
@@ -108,7 +108,7 @@
<div
class=
"col-sm-5"
style=
"padding-left: 0;padding-right: 0"
>
<div
class=
"panel panel-primary"
>
<div
class=
"panel-heading"
>
<i
class=
"fa fa-info-circle"
></i>
{% trans 'Quick
modify
' %}
<i
class=
"fa fa-info-circle"
></i>
{% trans 'Quick
update
' %}
</div>
<div
class=
"panel-body"
>
<table
class=
"table"
>
...
...
@@ -191,7 +191,7 @@
<tr>
<td
><b
class=
"bdg_user_group"
data-gid=
{{
group.id
}}
>
{{ group.name }}
</b></td>
<td>
<button
class=
"btn btn-danger btn-
sm
btn_delete_user_group"
type=
"button"
style=
"float: right;"
><i
class=
"fa fa-minus"
></i></button>
<button
class=
"btn btn-danger btn-
xs
btn_delete_user_group"
type=
"button"
style=
"float: right;"
><i
class=
"fa fa-minus"
></i></button>
</td>
</tr>
{% endfor %}
...
...
apps/users/urls.py
浏览文件 @
409fac3e
...
...
@@ -16,7 +16,6 @@ urlpatterns = [
name
=
'reset-password-success'
),
url
(
r
'^user$'
,
views
.
UserListView
.
as_view
(),
name
=
'user-list'
),
url
(
r
'^user/(?P<pk>[0-9]+)$'
,
views
.
UserDetailView
.
as_view
(),
name
=
'user-detail'
),
url
(
r
'^user/(?P<pk>[0-9]+)/assets-perm$'
,
views
.
UserDetailView
.
as_view
(),
name
=
'user-detail'
),
url
(
r
'^user/create$'
,
views
.
UserCreateView
.
as_view
(),
name
=
'user-create'
),
url
(
r
'^user/(?P<pk>[0-9]+)/update$'
,
views
.
UserUpdateView
.
as_view
(),
name
=
'user-update'
),
url
(
r
'^user/(?P<pk>[0-9]+)/delete$'
,
views
.
UserDeleteView
.
as_view
(),
name
=
'user-delete'
),
...
...
apps/users/views.py
浏览文件 @
409fac3e
...
...
@@ -103,7 +103,7 @@ class UserCreateView(AdminUserRequiredMixin, SuccessMessageMixin, CreateView):
form_class
=
UserCreateForm
template_name
=
'users/user_create.html'
success_url
=
reverse_lazy
(
'users:user-list'
)
success_message
=
_
(
'Create user <a href="%s">%s</a> success.'
)
success_message
=
_
(
'Create user <a href="%s">%s</a> success
fully
.'
)
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
(
UserCreateView
,
self
).
get_context_data
(
**
kwargs
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录