Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
djangoldp
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Fay Arnold
djangoldp
Commits
63e5db0d
Commit
63e5db0d
authored
6 years ago
by
Sylvain Le Bon
Browse files
Options
Downloads
Patches
Plain Diff
bugfix: fixed error on lists
parent
4f113112
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
djangoldp/serializers.py
+8
-3
8 additions, 3 deletions
djangoldp/serializers.py
with
8 additions
and
3 deletions
djangoldp/serializers.py
+
8
−
3
View file @
63e5db0d
...
@@ -8,8 +8,7 @@ from rest_framework.utils.serializer_helpers import ReturnDict
...
@@ -8,8 +8,7 @@ from rest_framework.utils.serializer_helpers import ReturnDict
from
rest_framework.utils.field_mapping
import
get_nested_relation_kwargs
from
rest_framework.utils.field_mapping
import
get_nested_relation_kwargs
from
guardian.shortcuts
import
get_perms
from
guardian.shortcuts
import
get_perms
class
ContainerSerializer
(
ListSerializer
):
class
LDListMixin
:
id
=
''
def
to_internal_value
(
self
,
data
):
def
to_internal_value
(
self
,
data
):
data
=
json
.
loads
(
data
)
data
=
json
.
loads
(
data
)
if
isinstance
(
data
,
dict
):
if
isinstance
(
data
,
dict
):
...
@@ -23,10 +22,16 @@ class ContainerSerializer(ListSerializer):
...
@@ -23,10 +22,16 @@ class ContainerSerializer(ListSerializer):
parent_id
=
parent_id_field
.
get_url
(
instance
,
parent_id_field
.
view_name
,
context
[
'
request
'
],
context
[
'
format
'
])
parent_id
=
parent_id_field
.
get_url
(
instance
,
parent_id_field
.
view_name
,
context
[
'
request
'
],
context
[
'
format
'
])
self
.
id
=
parent_id
+
self
.
field_name
+
"
/
"
self
.
id
=
parent_id
+
self
.
field_name
+
"
/
"
return
super
().
get_attribute
(
instance
)
return
super
().
get_attribute
(
instance
)
class
ContainerSerializer
(
LDListMixin
,
ListSerializer
):
id
=
''
@property
@property
def
data
(
self
):
def
data
(
self
):
return
ReturnDict
(
super
(
ListSerializer
,
self
).
data
,
serializer
=
self
)
return
ReturnDict
(
super
(
ListSerializer
,
self
).
data
,
serializer
=
self
)
class
ManyJsonLdRelatedField
(
LDListMixin
,
ManyRelatedField
):
pass
class
JsonLdField
(
HyperlinkedRelatedField
):
class
JsonLdField
(
HyperlinkedRelatedField
):
def
__init__
(
self
,
view_name
=
None
,
**
kwargs
):
def
__init__
(
self
,
view_name
=
None
,
**
kwargs
):
super
().
__init__
(
view_name
,
**
kwargs
)
super
().
__init__
(
view_name
,
**
kwargs
)
...
@@ -59,7 +64,7 @@ class JsonLdRelatedField(JsonLdField):
...
@@ -59,7 +64,7 @@ class JsonLdRelatedField(JsonLdField):
for
key
in
kwargs
:
for
key
in
kwargs
:
if
key
in
MANY_RELATION_KWARGS
:
if
key
in
MANY_RELATION_KWARGS
:
list_kwargs
[
key
]
=
kwargs
[
key
]
list_kwargs
[
key
]
=
kwargs
[
key
]
return
ContainerSerializer
(
**
list_kwargs
)
return
ManyJsonLdRelatedField
(
**
list_kwargs
)
class
JsonLdIdentityField
(
JsonLdField
):
class
JsonLdIdentityField
(
JsonLdField
):
def
__init__
(
self
,
view_name
=
None
,
**
kwargs
):
def
__init__
(
self
,
view_name
=
None
,
**
kwargs
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment