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
699b8d99
Commit
699b8d99
authored
Apr 15, 2019
by
八千流
Committed by
老广
Apr 15, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 修改批量更新资产url过长导致的错误 (#2571)
parent
638ba316
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
48 additions
and
10 deletions
+48
-10
asset.py
apps/assets/api/asset.py
+22
-1
const.py
apps/assets/const.py
+3
-0
asset_list.html
apps/assets/templates/assets/asset_list.html
+17
-3
api_urls.py
apps/assets/urls/api_urls.py
+2
-0
asset.py
apps/assets/views/asset.py
+4
-6
No files found.
apps/assets/api/asset.py
View file @
699b8d99
# -*- coding: utf-8 -*-
#
import
uuid
import
random
from
rest_framework
import
generics
from
rest_framework.views
import
APIView
from
rest_framework.response
import
Response
from
rest_framework_bulk
import
BulkModelViewSet
from
rest_framework_bulk
import
ListBulkCreateUpdateDestroyAPIView
from
rest_framework.pagination
import
LimitOffsetPagination
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.shortcuts
import
get_object_or_404
from
django.urls
import
reverse_lazy
from
django.core.cache
import
cache
from
django.db.models
import
Q
from
common.mixins
import
IDInFilterMixin
from
common.utils
import
get_logger
from
common.permissions
import
IsOrgAdmin
,
IsOrgAdminOrAppUser
from
..const
import
CACHE_KEY_ASSET_BULK_UPDATE_ID_PREFIX
from
..models
import
Asset
,
AdminUser
,
Node
from
..
import
serializers
from
..tasks
import
update_asset_hardware_info_manual
,
\
...
...
@@ -25,7 +31,7 @@ logger = get_logger(__file__)
__all__
=
[
'AssetViewSet'
,
'AssetListUpdateApi'
,
'AssetRefreshHardwareApi'
,
'AssetAdminUserTestApi'
,
'AssetGatewayApi'
'AssetGatewayApi'
,
'AssetBulkUpdateSelectAPI'
]
...
...
@@ -92,6 +98,21 @@ class AssetListUpdateApi(IDInFilterMixin, ListBulkCreateUpdateDestroyAPIView):
permission_classes
=
(
IsOrgAdmin
,)
class
AssetBulkUpdateSelectAPI
(
APIView
):
permission_classes
=
(
IsOrgAdmin
,)
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
assets_id
=
request
.
data
.
get
(
'assets_id'
,
''
)
if
assets_id
:
spm
=
uuid
.
uuid4
()
.
hex
key
=
CACHE_KEY_ASSET_BULK_UPDATE_ID_PREFIX
.
format
(
spm
)
cache
.
set
(
key
,
assets_id
,
300
)
url
=
reverse_lazy
(
'assets:asset-bulk-update'
)
+
'?spm=
%
s'
%
spm
return
Response
({
'url'
:
url
})
error
=
_
(
'Please select assets that need to be updated'
)
return
Response
({
'error'
:
error
},
status
=
400
)
class
AssetRefreshHardwareApi
(
generics
.
RetrieveAPIView
):
"""
Refresh asset hardware info
...
...
apps/assets/const.py
View file @
699b8d99
...
...
@@ -48,3 +48,6 @@ TASK_OPTIONS = {
'timeout'
:
10
,
'forks'
:
10
,
}
CACHE_KEY_ASSET_BULK_UPDATE_ID_PREFIX
=
'_KEY_ASSET_BULK_UPDATE_ID_{}'
apps/assets/templates/assets/asset_list.html
View file @
699b8d99
...
...
@@ -657,9 +657,23 @@ $(document).ready(function(){
});
}
function
doUpdate
()
{
var
id_list_string
=
id_list
.
join
(
','
);
var
url
=
"{% url 'assets:asset-bulk-update' %}?assets_id="
+
id_list_string
;
location
.
href
=
url
var
data
=
{
'assets_id'
:
id_list
};
function
error
(
data
)
{
toastr
.
error
(
JSON
.
parse
(
data
).
error
)
}
function
success
(
data
)
{
location
.
href
=
data
.
url
;
}
APIUpdateAttr
({
'url'
:
"{% url 'api-assets:asset-bulk-update-select' %}"
,
'method'
:
'POST'
,
'body'
:
JSON
.
stringify
(
data
),
'flash_message'
:
false
,
'success'
:
success
,
'error'
:
error
,
})
}
function
doRemove
()
{
...
...
apps/assets/urls/api_urls.py
View file @
699b8d99
...
...
@@ -25,6 +25,8 @@ cmd_filter_router.register(r'rules', api.CommandFilterRuleViewSet, 'cmd-filter-r
urlpatterns
=
[
path
(
'assets-bulk/'
,
api
.
AssetListUpdateApi
.
as_view
(),
name
=
'asset-bulk-update'
),
path
(
'asset/update/select/'
,
api
.
AssetBulkUpdateSelectAPI
.
as_view
(),
name
=
'asset-bulk-update-select'
),
path
(
'assets/<uuid:pk>/refresh/'
,
api
.
AssetRefreshHardwareApi
.
as_view
(),
name
=
'asset-refresh'
),
path
(
'assets/<uuid:pk>/alive/'
,
...
...
apps/assets/views/asset.py
View file @
699b8d99
...
...
@@ -28,6 +28,7 @@ from common.mixins import JSONResponseMixin
from
common.utils
import
get_object_or_none
,
get_logger
from
common.permissions
import
AdminUserRequiredMixin
from
common.const
import
create_success_msg
,
update_success_msg
from
..const
import
CACHE_KEY_ASSET_BULK_UPDATE_ID_PREFIX
from
orgs.utils
import
current_org
from
..
import
forms
from
..models
import
Asset
,
AdminUser
,
SystemUser
,
Label
,
Node
,
Domain
...
...
@@ -120,15 +121,12 @@ class AssetBulkUpdateView(AdminUserRequiredMixin, ListView):
form
=
None
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
assets_id
=
self
.
request
.
GET
.
get
(
'assets_id'
,
''
)
self
.
id_list
=
[
i
for
i
in
assets_id
.
split
(
','
)]
spm
=
request
.
GET
.
get
(
'spm'
,
''
)
assets_id
=
cache
.
get
(
CACHE_KEY_ASSET_BULK_UPDATE_ID_PREFIX
.
format
(
spm
))
if
kwargs
.
get
(
'form'
):
self
.
form
=
kwargs
[
'form'
]
elif
assets_id
:
self
.
form
=
self
.
form_class
(
initial
=
{
'assets'
:
self
.
id_list
}
)
self
.
form
=
self
.
form_class
(
initial
=
{
'assets'
:
assets_id
})
else
:
self
.
form
=
self
.
form_class
()
return
super
()
.
get
(
request
,
*
args
,
**
kwargs
)
...
...
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