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
c0afeba2
Unverified
Commit
c0afeba2
authored
Sep 11, 2019
by
老广
Committed by
GitHub
Sep 11, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3208 from jumpserver/dev_serializer
[Bugfix] 解决批量创建系统用户等资源时,initial_data.get() 失败的问题
parents
c2ea867d
1eb2038e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
2 deletions
+14
-2
serializers.py
apps/common/mixins/serializers.py
+13
-1
serializers.py
apps/orgs/mixins/serializers.py
+1
-1
No files found.
apps/common/mixins/serializers.py
View file @
c0afeba2
...
...
@@ -5,7 +5,7 @@ from django.core.exceptions import ObjectDoesNotExist
from
rest_framework.utils
import
html
from
rest_framework.settings
import
api_settings
from
rest_framework.exceptions
import
ValidationError
from
rest_framework.fields
import
SkipField
from
rest_framework.fields
import
SkipField
,
empty
__all__
=
[
'BulkSerializerMixin'
,
'BulkListSerializerMixin'
]
...
...
@@ -36,6 +36,18 @@ class BulkSerializerMixin(object):
ret
[
id_attr
]
=
id_value
return
ret
def
run_validation
(
self
,
data
=
empty
):
"""
批量创建时,获取到的self.initial_data是list,
所以想用一个属性来存放当前操作的数据集,在validate_field中使用
:param data:
:return:
"""
# 只有批量创建的时候,才需要重写 initial_data
if
self
.
parent
:
self
.
initial_data
=
data
return
super
()
.
run_validation
(
data
)
class
BulkListSerializerMixin
(
object
):
"""
...
...
apps/orgs/mixins/serializers.py
View file @
c0afeba2
...
...
@@ -42,7 +42,7 @@ class OrgResourceSerializerMixin(serializers.Serializer):
return
fields
class
BulkOrgResourceSerializerMixin
(
OrgResourceSerializerMixin
,
Bulk
SerializerMixin
):
class
BulkOrgResourceSerializerMixin
(
BulkSerializerMixin
,
OrgResource
SerializerMixin
):
pass
...
...
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