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
992af0f1
Commit
992af0f1
authored
Apr 04, 2017
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Fixture] 拆分asset view
parent
ac3553ba
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
475 additions
and
2 deletions
+475
-2
__init__.py
apps/assets/views/__init__.py
+7
-0
admin_user.py
apps/assets/views/admin_user.py
+112
-0
asset.py
apps/assets/views/asset.py
+0
-0
group.py
apps/assets/views/group.py
+111
-0
idc.py
apps/assets/views/idc.py
+101
-0
system_user.py
apps/assets/views/system_user.py
+139
-0
export_init_data.sh
utils/export_init_data.sh
+5
-2
No files found.
apps/assets/views/__init__.py
0 → 100644
View file @
992af0f1
# coding:utf-8
from
.asset
import
*
from
.group
import
*
from
.idc
import
*
from
.system_user
import
*
from
.admin_user
import
*
apps/assets/views/admin_user.py
0 → 100644
View file @
992af0f1
# coding:utf-8
from
__future__
import
absolute_import
,
unicode_literals
from
django.utils.translation
import
ugettext
as
_
from
django.conf
import
settings
from
django.views.generic
import
TemplateView
,
ListView
,
View
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
..
import
forms
from
..models
import
Asset
,
AssetGroup
,
AdminUser
,
IDC
,
SystemUser
from
..hands
import
AdminUserRequiredMixin
__all__
=
[
'AdminUserCreateView'
,
'AdminUserDetailView'
,
'AdminUserDeleteView'
,
'AdminUserListView'
,
'AdminUserUpdateView'
,
]
class
AdminUserListView
(
AdminUserRequiredMixin
,
TemplateView
):
model
=
AdminUser
template_name
=
'assets/admin_user_list.html'
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
'app'
:
_
(
'Assets'
),
'action'
:
_
(
'Admin user list'
),
}
kwargs
.
update
(
context
)
return
super
(
AdminUserListView
,
self
)
.
get_context_data
(
**
kwargs
)
class
AdminUserCreateView
(
AdminUserRequiredMixin
,
SuccessMessageMixin
,
CreateView
):
model
=
AdminUser
form_class
=
forms
.
AdminUserForm
template_name
=
'assets/admin_user_create_update.html'
success_url
=
reverse_lazy
(
'assets:admin-user-list'
)
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
):
success_message
=
_
(
'Create admin user <a href="
%
s">
%
s</a> successfully.'
%
(
reverse_lazy
(
'assets:admin-user-detail'
,
kwargs
=
{
'pk'
:
self
.
object
.
pk
}),
self
.
object
.
name
,
))
return
success_message
def
form_invalid
(
self
,
form
):
return
super
(
AdminUserCreateView
,
self
)
.
form_invalid
(
form
)
class
AdminUserUpdateView
(
AdminUserRequiredMixin
,
UpdateView
):
model
=
AdminUser
form_class
=
forms
.
AdminUserForm
template_name
=
'assets/admin_user_create_update.html'
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
'app'
:
'assets'
,
'action'
:
'Update admin user'
}
kwargs
.
update
(
context
)
return
super
(
AdminUserUpdateView
,
self
)
.
get_context_data
(
**
kwargs
)
def
get_success_url
(
self
):
success_url
=
reverse_lazy
(
'assets:admin-user-detail'
,
kwargs
=
{
'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
):
asset_groups
=
AssetGroup
.
objects
.
all
()
assets
=
self
.
get_queryset
()
context
=
{
'app'
:
'assets'
,
'action'
:
'Admin user detail'
,
'assets_remain'
:
[
asset
for
asset
in
Asset
.
objects
.
all
()
if
asset
not
in
assets
],
'asset_groups'
:
asset_groups
,
}
kwargs
.
update
(
context
)
return
super
(
AdminUserDetailView
,
self
)
.
get_context_data
(
**
kwargs
)
class
AdminUserDeleteView
(
AdminUserRequiredMixin
,
DeleteView
):
model
=
AdminUser
template_name
=
'assets/delete_confirm.html'
success_url
=
reverse_lazy
(
'assets:admin-user-list'
)
apps/assets/views.py
→
apps/assets/views
/asset
.py
View file @
992af0f1
This diff is collapsed.
Click to expand it.
apps/assets/views/group.py
0 → 100644
View file @
992af0f1
# coding:utf-8
from
__future__
import
absolute_import
,
unicode_literals
from
django.utils.translation
import
ugettext
as
_
from
django.views.generic
import
TemplateView
,
ListView
,
View
from
django.views.generic.edit
import
CreateView
,
DeleteView
,
FormView
,
UpdateView
from
django.urls
import
reverse_lazy
from
django.views.generic.detail
import
DetailView
,
SingleObjectMixin
from
django.shortcuts
import
get_object_or_404
,
reverse
,
redirect
from
..
import
forms
from
..models
import
Asset
,
AssetGroup
,
AdminUser
,
IDC
,
SystemUser
from
..hands
import
AdminUserRequiredMixin
__all__
=
[
'AssetGroupCreateView'
,
'AssetGroupDetailView'
,
'AssetGroupUpdateView'
,
'AssetGroupListView'
,
'AssetGroupDeleteView'
,
]
class
AssetGroupCreateView
(
AdminUserRequiredMixin
,
CreateView
):
model
=
AssetGroup
form_class
=
forms
.
AssetGroupForm
template_name
=
'assets/asset_group_create.html'
success_url
=
reverse_lazy
(
'assets:asset-group-list'
)
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
'app'
:
_
(
'Assets'
),
'action'
:
_
(
'Create asset group'
),
'assets_count'
:
0
,
}
kwargs
.
update
(
context
)
return
super
(
AssetGroupCreateView
,
self
)
.
get_context_data
(
**
kwargs
)
def
form_valid
(
self
,
form
):
asset_group
=
form
.
save
()
assets_id_list
=
self
.
request
.
POST
.
getlist
(
'assets'
,
[])
assets
=
[
get_object_or_404
(
Asset
,
id
=
int
(
asset_id
))
for
asset_id
in
assets_id_list
]
asset_group
.
created_by
=
self
.
request
.
user
.
username
or
'Admin'
asset_group
.
assets
.
add
(
*
tuple
(
assets
))
asset_group
.
save
()
return
super
(
AssetGroupCreateView
,
self
)
.
form_valid
(
form
)
class
AssetGroupListView
(
AdminUserRequiredMixin
,
TemplateView
):
template_name
=
'assets/asset_group_list.html'
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
'app'
:
_
(
'Assets'
),
'action'
:
_
(
'Asset group list'
),
'assets'
:
Asset
.
objects
.
all
(),
'system_users'
:
SystemUser
.
objects
.
all
(),
'keyword'
:
self
.
request
.
GET
.
get
(
'keyword'
,
''
)
}
kwargs
.
update
(
context
)
return
super
(
AssetGroupListView
,
self
)
.
get_context_data
(
**
kwargs
)
class
AssetGroupDetailView
(
AdminUserRequiredMixin
,
DetailView
):
model
=
AssetGroup
template_name
=
'assets/asset_group_detail.html'
context_object_name
=
'asset_group'
def
get_context_data
(
self
,
**
kwargs
):
assets_remain
=
Asset
.
objects
.
exclude
(
id__in
=
self
.
object
.
assets
.
all
())
system_users
=
self
.
object
.
system_users
.
all
()
system_users_remain
=
SystemUser
.
objects
.
exclude
(
id__in
=
system_users
)
context
=
{
'app'
:
_
(
'Assets'
),
'action'
:
_
(
'Asset group detail'
),
'assets_remain'
:
assets_remain
,
'assets'
:
[
asset
for
asset
in
Asset
.
objects
.
all
()
if
asset
not
in
assets_remain
],
'system_users'
:
system_users
,
'system_users_remain'
:
system_users_remain
,
}
kwargs
.
update
(
context
)
return
super
(
AssetGroupDetailView
,
self
)
.
get_context_data
(
**
kwargs
)
class
AssetGroupUpdateView
(
AdminUserRequiredMixin
,
UpdateView
):
model
=
AssetGroup
form_class
=
forms
.
AssetGroupForm
template_name
=
'assets/asset_group_create.html'
success_url
=
reverse_lazy
(
'assets:asset-group-list'
)
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
self
.
object
=
self
.
get_object
(
queryset
=
AssetGroup
.
objects
.
all
())
return
super
(
AssetGroupUpdateView
,
self
)
.
get
(
request
,
*
args
,
**
kwargs
)
def
get_context_data
(
self
,
**
kwargs
):
assets_all
=
self
.
object
.
assets
.
all
()
context
=
{
'app'
:
_
(
'Assets'
),
'action'
:
_
(
'Create asset group'
),
'assets_on_list'
:
assets_all
,
'assets_count'
:
len
(
assets_all
),
'group_id'
:
self
.
object
.
id
,
}
kwargs
.
update
(
context
)
return
super
(
AssetGroupUpdateView
,
self
)
.
get_context_data
(
**
kwargs
)
class
AssetGroupDeleteView
(
AdminUserRequiredMixin
,
DeleteView
):
template_name
=
'assets/delete_confirm.html'
model
=
AssetGroup
success_url
=
reverse_lazy
(
'assets:asset-group-list'
)
apps/assets/views/idc.py
0 → 100644
View file @
992af0f1
# coding:utf-8
from
__future__
import
absolute_import
,
unicode_literals
from
django.utils.translation
import
ugettext
as
_
from
django.views.generic
import
TemplateView
,
ListView
,
View
from
django.views.generic.edit
import
CreateView
,
DeleteView
,
FormView
,
UpdateView
from
django.urls
import
reverse_lazy
from
django.views.generic.detail
import
DetailView
,
SingleObjectMixin
from
..
import
forms
from
..models
import
Asset
,
AssetGroup
,
AdminUser
,
IDC
,
SystemUser
from
..hands
import
AdminUserRequiredMixin
__all__
=
[
'IDCListView'
,
'IDCCreateView'
,
'IDCUpdateView'
,
'IDCDetailView'
,
'IDCDeleteView'
,
'IDCAssetsView'
]
class
IDCListView
(
AdminUserRequiredMixin
,
TemplateView
):
template_name
=
'assets/idc_list.html'
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
'app'
:
_
(
'Assets'
),
'action'
:
_
(
'IDC list'
),
# 'keyword': self.request.GET.get('keyword', '')
}
kwargs
.
update
(
context
)
return
super
(
IDCListView
,
self
)
.
get_context_data
(
**
kwargs
)
class
IDCCreateView
(
AdminUserRequiredMixin
,
CreateView
):
model
=
IDC
form_class
=
forms
.
IDCForm
template_name
=
'assets/idc_create_update.html'
success_url
=
reverse_lazy
(
'assets:idc-list'
)
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
'app'
:
_
(
'assets'
),
'action'
:
_
(
'Create IDC'
),
}
kwargs
.
update
(
context
)
return
super
(
IDCCreateView
,
self
)
.
get_context_data
(
**
kwargs
)
def
form_valid
(
self
,
form
):
idc
=
form
.
save
(
commit
=
False
)
idc
.
created_by
=
self
.
request
.
user
.
username
or
'System'
idc
.
save
()
return
super
(
IDCCreateView
,
self
)
.
form_valid
(
form
)
class
IDCUpdateView
(
AdminUserRequiredMixin
,
UpdateView
):
model
=
IDC
form_class
=
forms
.
IDCForm
template_name
=
'assets/idc_create_update.html'
context_object_name
=
'idc'
success_url
=
reverse_lazy
(
'assets:idc-list'
)
def
form_valid
(
self
,
form
):
idc
=
form
.
save
(
commit
=
False
)
idc
.
save
()
return
super
(
IDCUpdateView
,
self
)
.
form_valid
(
form
)
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
'app'
:
_
(
'assets'
),
'action'
:
_
(
'Update IDC'
),
}
kwargs
.
update
(
context
)
return
super
(
IDCUpdateView
,
self
)
.
get_context_data
(
**
kwargs
)
class
IDCDetailView
(
AdminUserRequiredMixin
,
DetailView
):
model
=
IDC
template_name
=
'assets/idc_detail.html'
context_object_name
=
'idc'
class
IDCAssetsView
(
AdminUserRequiredMixin
,
DetailView
):
model
=
IDC
template_name
=
'assets/idc_assets.html'
context_object_name
=
'idc'
def
get_context_data
(
self
,
**
kwargs
):
assets_remain
=
Asset
.
objects
.
exclude
(
id__in
=
self
.
object
.
assets
.
all
())
context
=
{
'app'
:
_
(
'Assets'
),
'action'
:
_
(
'Asset detail'
),
'groups'
:
AssetGroup
.
objects
.
all
(),
'system_users'
:
SystemUser
.
objects
.
all
(),
'assets_remain'
:
assets_remain
,
'assets'
:
[
asset
for
asset
in
Asset
.
objects
.
all
()
if
asset
not
in
assets_remain
],
}
kwargs
.
update
(
context
)
return
super
(
IDCAssetsView
,
self
)
.
get_context_data
(
**
kwargs
)
class
IDCDeleteView
(
AdminUserRequiredMixin
,
DeleteView
):
model
=
IDC
template_name
=
'assets/delete_confirm.html'
success_url
=
reverse_lazy
(
'assets:idc-list'
)
apps/assets/views/system_user.py
0 → 100644
View file @
992af0f1
# ~*~ coding: utf-8 ~*~
from
__future__
import
absolute_import
,
unicode_literals
from
django.utils.translation
import
ugettext
as
_
from
django.conf
import
settings
from
django.db
import
transaction
from
django.views.generic
import
TemplateView
,
ListView
,
View
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
..
import
forms
from
..models
import
Asset
,
AssetGroup
,
AdminUser
,
IDC
,
SystemUser
from
..hands
import
AdminUserRequiredMixin
__all__
=
[
'SystemUserCreateView'
,
'SystemUserUpdateView'
,
'SystemUserDetailView'
,
'SystemUserDeleteView'
,
'SystemUserAssetView'
,
'SystemUserListView'
,
]
class
SystemUserListView
(
AdminUserRequiredMixin
,
TemplateView
):
template_name
=
'assets/system_user_list.html'
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
'app'
:
_
(
'Assets'
),
'action'
:
_
(
'System user list'
),
}
kwargs
.
update
(
context
)
return
super
(
SystemUserListView
,
self
)
.
get_context_data
(
**
kwargs
)
class
SystemUserCreateView
(
AdminUserRequiredMixin
,
SuccessMessageMixin
,
CreateView
):
model
=
SystemUser
form_class
=
forms
.
SystemUserForm
template_name
=
'assets/system_user_create.html'
success_url
=
reverse_lazy
(
'assets:system-user-list'
)
@transaction.atomic
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
return
super
(
SystemUserCreateView
,
self
)
.
post
(
request
,
*
args
,
**
kwargs
)
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
'app'
:
_
(
'Assets'
),
'action'
:
_
(
'Create system user'
),
}
kwargs
.
update
(
context
)
return
super
(
SystemUserCreateView
,
self
)
.
get_context_data
(
**
kwargs
)
def
form_invalid
(
self
,
form
):
print
(
form
.
errors
)
return
super
(
SystemUserCreateView
,
self
)
.
form_invalid
(
form
)
def
get_success_message
(
self
,
cleaned_data
):
success_message
=
_
(
'Create system user <a href="
%
s">
%
s</a> successfully.'
%
(
reverse_lazy
(
'assets:system-user-detail'
,
kwargs
=
{
'pk'
:
self
.
object
.
pk
}),
self
.
object
.
name
,
))
return
success_message
class
SystemUserUpdateView
(
AdminUserRequiredMixin
,
UpdateView
):
model
=
SystemUser
form_class
=
forms
.
SystemUserForm
template_name
=
'assets/system_user_update.html'
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
'app'
:
_
(
'Assets'
),
'action'
:
_
(
'Update system user'
)
}
kwargs
.
update
(
context
)
return
super
(
SystemUserUpdateView
,
self
)
.
get_context_data
(
**
kwargs
)
def
get_success_url
(
self
):
success_url
=
reverse_lazy
(
'assets:system-user-detail'
,
kwargs
=
{
'pk'
:
self
.
object
.
pk
})
return
success_url
class
SystemUserDetailView
(
AdminUserRequiredMixin
,
DetailView
):
template_name
=
'assets/system_user_detail.html'
context_object_name
=
'system_user'
model
=
SystemUser
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
'app'
:
_
(
'Assets'
),
'action'
:
_
(
'System user detail'
)
}
kwargs
.
update
(
context
)
return
super
(
SystemUserDetailView
,
self
)
.
get_context_data
(
**
kwargs
)
class
SystemUserDeleteView
(
AdminUserRequiredMixin
,
DeleteView
):
model
=
SystemUser
template_name
=
'assets/delete_confirm.html'
success_url
=
reverse_lazy
(
'assets:system-user-list'
)
class
SystemUserAssetView
(
AdminUserRequiredMixin
,
SingleObjectMixin
,
ListView
):
paginate_by
=
settings
.
CONFIG
.
DISPLAY_PER_PAGE
template_name
=
'assets/system_user_asset.html'
context_object_name
=
'system_user'
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
self
.
object
=
self
.
get_object
(
queryset
=
SystemUser
.
objects
.
all
())
return
super
(
SystemUserAssetView
,
self
)
.
get
(
request
,
*
args
,
**
kwargs
)
def
get_asset_groups
(
self
):
return
self
.
object
.
asset_groups
.
all
()
# Todo: queryset default order by connectivity, need ops support
def
get_queryset
(
self
):
return
list
(
self
.
object
.
get_assets
())
def
get_context_data
(
self
,
**
kwargs
):
asset_groups
=
self
.
get_asset_groups
()
assets
=
self
.
get_queryset
()
context
=
{
'app'
:
'assets'
,
'action'
:
'System user asset'
,
'assets_remain'
:
[
asset
for
asset
in
Asset
.
objects
.
all
()
if
asset
not
in
assets
],
'asset_groups'
:
asset_groups
,
'asset_groups_remain'
:
[
asset_group
for
asset_group
in
AssetGroup
.
objects
.
all
()
if
asset_group
not
in
asset_groups
]
}
kwargs
.
update
(
context
)
return
super
(
SystemUserAssetView
,
self
)
.
get_context_data
(
**
kwargs
)
utils/export_init_data.sh
View file @
992af0f1
...
...
@@ -3,10 +3,13 @@
python2.7 ../apps/manage.py shell
<<
EOF
from users.models import *
init_
all_models
()
init_
model
()
from assets.models import *
init_all_models()
init_model()
from audits.models import LoginLog
LoginLog.objects.all().delete()
EOF
...
...
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