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
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gushitong
gm-serializer
Commits
2c6c19d5
Commit
2c6c19d5
authored
Jul 06, 2017
by
gushitong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
重命名
parent
78c94853
Hide 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'
gm_serializer/error.py
View file @
2c6c19d5
class
Lazy
ObjNotExist
(
Exception
):
class
Magic
ObjNotExist
(
Exception
):
pass
class
Multi
Lazy
ObjFound
(
Exception
):
class
Multi
Magic
ObjFound
(
Exception
):
pass
gm_serializer/serializers/__init__.py
View file @
2c6c19d5
from
rest_framework.serializers
import
*
from
.serializer
import
GmModel
Serializer
from
.serializer
import
Magic
Serializer
from
.field
import
MagicField
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
from
rest_framework
import
serializers
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
.
extend
([
'lazy'
,
'lazy_field_ids'
])
class
GmModel
Serializer
(
serializers
.
ModelSerializer
):
class
Magic
Serializer
(
serializers
.
ModelSerializer
):
@classmethod
def
many_init
(
cls
,
*
args
,
**
kwargs
):
...
...
@@ -31,7 +31,7 @@ class GmModelSerializer(serializers.ModelSerializer):
})
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
)
@classmethod
...
...
@@ -55,12 +55,12 @@ class GmModelSerializer(serializers.ModelSerializer):
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
):
self
.
lazy
=
kwargs
.
pop
(
'lazy'
,
False
)
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
):
iterable
=
data
.
all
()
if
isinstance
(
data
,
models
.
Manager
)
else
data
...
...
@@ -102,11 +102,11 @@ class GmListSerializer(ListSerializer):
future
=
list
(
filter
(
lambda
item
:
item
[
'id'
]
==
lazy_id
,
futures
))
if
len
(
future
)
>
1
:
raise
Multi
Lazy
ObjFound
raise
Multi
Magic
ObjFound
elif
len
(
future
)
==
1
:
setattr
(
iterable
[
i
],
field
,
future
[
0
])
else
:
raise
Lazy
ObjNotExist
raise
Magic
ObjNotExist
return
iterable
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