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
75e67410
Commit
75e67410
authored
Aug 13, 2018
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Bugfix] 修复批量更新资产和用户的bug
parent
c9d137bc
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
17 additions
and
44 deletions
+17
-44
asset.py
apps/assets/views/asset.py
+3
-26
django.mo
apps/i18n/zh/LC_MESSAGES/django.mo
+0
-0
django.po
apps/i18n/zh/LC_MESSAGES/django.po
+0
-0
mixins.py
apps/orgs/mixins.py
+4
-5
utils.py
apps/orgs/utils.py
+2
-5
forms.py
apps/users/forms.py
+4
-4
user.py
apps/users/views/user.py
+3
-4
requirements.txt
requirements/requirements.txt
+1
-0
No files found.
apps/assets/views/asset.py
View file @
75e67410
...
...
@@ -9,6 +9,7 @@ import chardet
from
io
import
StringIO
from
django.db
import
transaction
from
django.contrib
import
messages
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.views.generic
import
TemplateView
,
ListView
,
View
from
django.views.generic.edit
import
CreateView
,
DeleteView
,
FormView
,
UpdateView
...
...
@@ -76,14 +77,6 @@ class AssetCreateView(AdminUserRequiredMixin, SuccessMessageMixin, CreateView):
template_name
=
'assets/asset_create.html'
success_url
=
reverse_lazy
(
'assets:asset-list'
)
# def form_valid(self, form):
# print("form valid")
# asset = form.save()
# asset.created_by = self.request.user.username or 'Admin'
# asset.date_created = timezone.now()
# asset.save()
# return super().form_valid(form)
def
get_form
(
self
,
form_class
=
None
):
form
=
super
()
.
get_form
(
form_class
=
form_class
)
node_id
=
self
.
request
.
GET
.
get
(
"node_id"
)
...
...
@@ -106,29 +99,12 @@ class AssetCreateView(AdminUserRequiredMixin, SuccessMessageMixin, CreateView):
return
create_success_msg
%
({
"name"
:
cleaned_data
[
"hostname"
]})
# class AssetModalListView(AdminUserRequiredMixin, ListView):
# paginate_by = settings.DISPLAY_PER_PAGE
# model = Asset
# context_object_name = 'asset_modal_list'
# template_name = 'assets/_asset_list_modal.html'
#
# def get_context_data(self, **kwargs):
# assets = Asset.objects.all()
# assets_id = self.request.GET.get('assets_id', '')
# assets_id_list = [i for i in assets_id.split(',') if i.isdigit()]
# context = {
# 'all_assets': assets_id_list,
# 'assets': assets
# }
# kwargs.update(context)
# return super().get_context_data(**kwargs)
class
AssetBulkUpdateView
(
AdminUserRequiredMixin
,
ListView
):
model
=
Asset
form_class
=
forms
.
AssetBulkUpdateForm
template_name
=
'assets/asset_bulk_update.html'
success_url
=
reverse_lazy
(
'assets:asset-list'
)
success_message
=
_
(
"Bulk update asset success"
)
id_list
=
None
form
=
None
...
...
@@ -150,6 +126,7 @@ class AssetBulkUpdateView(AdminUserRequiredMixin, ListView):
form
=
self
.
form_class
(
request
.
POST
)
if
form
.
is_valid
():
form
.
save
()
messages
.
success
(
request
,
self
.
success_message
)
return
redirect
(
self
.
success_url
)
else
:
return
self
.
get
(
request
,
form
=
form
,
*
args
,
**
kwargs
)
...
...
apps/i18n/zh/LC_MESSAGES/django.mo
View file @
75e67410
No preview for this file type
apps/i18n/zh/LC_MESSAGES/django.po
View file @
75e67410
This diff is collapsed.
Click to expand it.
apps/orgs/mixins.py
View file @
75e67410
# -*- coding: utf-8 -*-
#
from
threading
import
local
from
werkzeug.local
import
Local
from
django.db
import
models
from
django.db.models
import
Q
from
django.shortcuts
import
redirect
import
warnings
from
django.forms
import
ModelForm
from
django.http.response
import
HttpResponseForbidden
...
...
@@ -14,7 +13,7 @@ from .utils import current_org, set_current_org, set_to_root_org
from
.models
import
Organization
logger
=
get_logger
(
__file__
)
tl
=
l
ocal
()
tl
=
L
ocal
()
__all__
=
[
'OrgManager'
,
'OrgViewGenericMixin'
,
'OrgModelMixin'
,
'OrgModelForm'
,
...
...
@@ -93,8 +92,8 @@ class RootOrgViewMixin:
class
OrgModelForm
(
ModelForm
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
()
.
__init__
(
*
args
,
**
kwargs
)
if
'initial'
not
in
kwargs
:
return
#
if 'initial' not in kwargs:
#
return
for
name
,
field
in
self
.
fields
.
items
():
if
not
hasattr
(
field
,
'queryset'
):
continue
...
...
apps/orgs/utils.py
View file @
75e67410
...
...
@@ -2,16 +2,13 @@
#
from
functools
import
partial
from
werkzeug.local
import
Local
from
common.utils
import
LocalProxy
from
.models
import
Organization
try
:
from
threading
import
local
except
ImportError
:
from
django.utils._threading_local
import
local
_thread_locals
=
l
ocal
()
_thread_locals
=
L
ocal
()
def
get_org_from_request
(
request
):
...
...
apps/users/forms.py
View file @
75e67410
...
...
@@ -258,12 +258,12 @@ class UserPublicKeyForm(forms.Form):
UserPublicKeyForm
.
verbose_name
=
_
(
"Public key"
)
class
UserBulkUpdateForm
(
forms
.
ModelForm
):
class
UserBulkUpdateForm
(
Org
ModelForm
):
users
=
forms
.
ModelMultipleChoiceField
(
required
=
True
,
help_text
=
'* required'
,
label
=
_
(
'Select users'
),
queryset
=
User
.
objects
.
all
(),
queryset
=
User
.
objects
.
all
(),
widget
=
forms
.
SelectMultiple
(
attrs
=
{
'class'
:
'select2'
,
...
...
@@ -274,12 +274,12 @@ class UserBulkUpdateForm(forms.ModelForm):
class
Meta
:
model
=
User
fields
=
[
'users'
,
'
role'
,
'
groups'
,
'date_expired'
]
fields
=
[
'users'
,
'groups'
,
'date_expired'
]
widgets
=
{
"groups"
:
forms
.
SelectMultiple
(
attrs
=
{
'class'
:
'select2'
,
'data-placeholder'
:
_
(
'
Select users
'
)
'data-placeholder'
:
_
(
'
User group
'
)
}
)
}
...
...
apps/users/views/user.py
View file @
75e67410
...
...
@@ -24,9 +24,9 @@ from django.views import View
from
django.views.generic.base
import
TemplateView
from
django.db
import
transaction
from
django.views.generic.edit
import
(
CreateView
,
UpdateView
,
Form
Mixin
,
Form
View
CreateView
,
UpdateView
,
FormView
)
from
django.views.generic.detail
import
DetailView
,
SingleObjectMixin
from
django.views.generic.detail
import
DetailView
from
django.views.decorators.csrf
import
csrf_exempt
from
django.contrib.auth
import
logout
as
auth_logout
...
...
@@ -41,7 +41,6 @@ from ..utils import generate_otp_uri, check_otp_code, \
get_user_or_tmp_user
,
get_password_check_rules
,
check_password_rules
,
\
is_need_unblock
from
..signals
import
post_user_create
from
..tasks
import
write_login_log_async
__all__
=
[
'UserListView'
,
'UserCreateView'
,
'UserDetailView'
,
...
...
@@ -171,7 +170,7 @@ class UserBulkUpdateView(AdminUserRequiredMixin, TemplateView):
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
'app'
:
'Assets'
,
'action'
:
'Bulk update asset'
,
'action'
:
_
(
'Bulk update user'
)
,
'form'
:
self
.
form
,
'users_selected'
:
self
.
id_list
,
}
...
...
requirements/requirements.txt
View file @
75e67410
...
...
@@ -70,3 +70,4 @@ uritemplate==3.0.0
urllib3==1.22
vine==1.1.4
drf-yasg==1.9.1
Werkzeug==0.14.1
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