Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
gm-serializer
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
backend
gm-serializer
Commits
2c6c19d5
Commit
2c6c19d5
authored
Jul 06, 2017
by
gushitong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
重命名
parent
78c94853
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
11 deletions
+15
-11
__init__.py
gm_serializer/__init__.py
+3
-1
error.py
gm_serializer/error.py
+2
-2
__init__.py
gm_serializer/serializers/__init__.py
+3
-1
serializer.py
gm_serializer/serializers/serializer.py
+7
-7
No files found.
gm_serializer/__init__.py
View file @
2c6c19d5
__version__
=
'0.0.
2
'
__version__
=
'0.0.
3
'
__author__
=
'gushitong@gmei.com'
__author__
=
'gushitong@gmei.com'
gm_serializer/error.py
View file @
2c6c19d5
class
Lazy
ObjNotExist
(
Exception
):
class
Magic
ObjNotExist
(
Exception
):
pass
pass
class
Multi
Lazy
ObjFound
(
Exception
):
class
Multi
Magic
ObjFound
(
Exception
):
pass
pass
gm_serializer/serializers/__init__.py
View file @
2c6c19d5
from
rest_framework.serializers
import
*
from
rest_framework.serializers
import
*
from
.serializer
import
GmModel
Serializer
from
.serializer
import
Magic
Serializer
from
.field
import
MagicField
from
.field
import
MagicField
from
.validator
import
BlacklistValidator
,
FilterWordValidator
from
.validator
import
BlacklistValidator
,
FilterWordValidator
from
gm_serializer.error
import
MagicObjNotExist
,
MultiMagicObjFound
\ No newline at end of file
gm_serializer/serializers/serializer.py
View file @
2c6c19d5
...
@@ -3,13 +3,13 @@ from django.db import models
...
@@ -3,13 +3,13 @@ from django.db import models
from
rest_framework
import
serializers
from
rest_framework
import
serializers
from
rest_framework.serializers
import
ListSerializer
from
rest_framework.serializers
import
ListSerializer
from
gm_serializer.error
import
LazyObjNotExist
,
MultiLazy
ObjFound
from
gm_serializer.error
import
MagicObjNotExist
,
MultiMagic
ObjFound
LIST_SERIALIZER_KWARGS
=
list
(
serializers
.
LIST_SERIALIZER_KWARGS
)
LIST_SERIALIZER_KWARGS
=
list
(
serializers
.
LIST_SERIALIZER_KWARGS
)
LIST_SERIALIZER_KWARGS
.
extend
([
'lazy'
,
'lazy_field_ids'
])
LIST_SERIALIZER_KWARGS
.
extend
([
'lazy'
,
'lazy_field_ids'
])
class
GmModel
Serializer
(
serializers
.
ModelSerializer
):
class
Magic
Serializer
(
serializers
.
ModelSerializer
):
@classmethod
@classmethod
def
many_init
(
cls
,
*
args
,
**
kwargs
):
def
many_init
(
cls
,
*
args
,
**
kwargs
):
...
@@ -31,7 +31,7 @@ class GmModelSerializer(serializers.ModelSerializer):
...
@@ -31,7 +31,7 @@ class GmModelSerializer(serializers.ModelSerializer):
})
})
meta
=
getattr
(
cls
,
'Meta'
,
None
)
meta
=
getattr
(
cls
,
'Meta'
,
None
)
list_serializer_class
=
getattr
(
meta
,
'list_serializer_class'
,
Gm
ListSerializer
)
list_serializer_class
=
getattr
(
meta
,
'list_serializer_class'
,
Magic
ListSerializer
)
return
list_serializer_class
(
*
args
,
**
list_kwargs
)
return
list_serializer_class
(
*
args
,
**
list_kwargs
)
@classmethod
@classmethod
...
@@ -55,12 +55,12 @@ class GmModelSerializer(serializers.ModelSerializer):
...
@@ -55,12 +55,12 @@ class GmModelSerializer(serializers.ModelSerializer):
return
[
getattr
(
obj
,
"
%
s_id"
%
field_name
)
for
obj
in
obj_list
]
return
[
getattr
(
obj
,
"
%
s_id"
%
field_name
)
for
obj
in
obj_list
]
class
Gm
ListSerializer
(
ListSerializer
):
class
Magic
ListSerializer
(
ListSerializer
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
self
.
lazy
=
kwargs
.
pop
(
'lazy'
,
False
)
self
.
lazy
=
kwargs
.
pop
(
'lazy'
,
False
)
self
.
lazy_fields
=
kwargs
.
pop
(
'lazy_fields'
,
None
)
self
.
lazy_fields
=
kwargs
.
pop
(
'lazy_fields'
,
None
)
super
(
Gm
ListSerializer
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
super
(
Magic
ListSerializer
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
def
to_representation
(
self
,
data
):
def
to_representation
(
self
,
data
):
iterable
=
data
.
all
()
if
isinstance
(
data
,
models
.
Manager
)
else
data
iterable
=
data
.
all
()
if
isinstance
(
data
,
models
.
Manager
)
else
data
...
@@ -102,11 +102,11 @@ class GmListSerializer(ListSerializer):
...
@@ -102,11 +102,11 @@ class GmListSerializer(ListSerializer):
future
=
list
(
filter
(
lambda
item
:
item
[
'id'
]
==
lazy_id
,
futures
))
future
=
list
(
filter
(
lambda
item
:
item
[
'id'
]
==
lazy_id
,
futures
))
if
len
(
future
)
>
1
:
if
len
(
future
)
>
1
:
raise
Multi
Lazy
ObjFound
raise
Multi
Magic
ObjFound
elif
len
(
future
)
==
1
:
elif
len
(
future
)
==
1
:
setattr
(
iterable
[
i
],
field
,
future
[
0
])
setattr
(
iterable
[
i
],
field
,
future
[
0
])
else
:
else
:
raise
Lazy
ObjNotExist
raise
Magic
ObjNotExist
return
iterable
return
iterable
def
update
(
self
,
instance
,
validated_data
):
def
update
(
self
,
instance
,
validated_data
):
...
...
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