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
djangoldp-packages
djangoldp
Commits
4f113112
Commit
4f113112
authored
6 years ago
by
Sylvain Le Bon
Browse files
Options
Downloads
Patches
Plain Diff
bugfix: fixed ids of nested containers
parent
da4384bf
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
djangoldp/serializers.py
+14
-18
14 additions, 18 deletions
djangoldp/serializers.py
setup.py
+1
-1
1 addition, 1 deletion
setup.py
with
15 additions
and
19 deletions
djangoldp/serializers.py
+
14
−
18
View file @
4f113112
...
@@ -10,10 +10,18 @@ from guardian.shortcuts import get_perms
...
@@ -10,10 +10,18 @@ from guardian.shortcuts import get_perms
class
ContainerSerializer
(
ListSerializer
):
class
ContainerSerializer
(
ListSerializer
):
id
=
''
id
=
''
def
to_representation
(
self
,
data
):
def
to_internal_value
(
self
,
data
):
return
{
'
@id
'
:
self
.
id
,
'
ldp:contains
'
:
super
(
ContainerSerializer
,
self
).
to_representation
(
data
)}
data
=
json
.
loads
(
data
)
if
isinstance
(
data
,
dict
):
data
=
[
data
]
return
[
self
.
child_relation
.
to_internal_value
(
item
[
'
@id
'
])
for
item
in
data
]
def
to_representation
(
self
,
value
):
return
{
'
@id
'
:
self
.
id
,
'
ldp:contains
'
:
super
().
to_representation
(
value
)}
def
get_attribute
(
self
,
instance
):
def
get_attribute
(
self
,
instance
):
self
.
id
=
self
.
parent
.
context
[
'
request
'
].
get_full_path
()
+
self
.
field_name
+
"
/
"
parent_id_field
=
self
.
parent
.
fields
[
self
.
parent
.
url_field_name
]
context
=
self
.
parent
.
context
parent_id
=
parent_id_field
.
get_url
(
instance
,
parent_id_field
.
view_name
,
context
[
'
request
'
],
context
[
'
format
'
])
self
.
id
=
parent_id
+
self
.
field_name
+
"
/
"
return
super
().
get_attribute
(
instance
)
return
super
().
get_attribute
(
instance
)
@property
@property
def
data
(
self
):
def
data
(
self
):
...
@@ -32,18 +40,6 @@ class JsonLdField(HyperlinkedRelatedField):
...
@@ -32,18 +40,6 @@ class JsonLdField(HyperlinkedRelatedField):
except
MultiValueDictKeyError
:
except
MultiValueDictKeyError
:
pass
pass
class
ManyJsonLdRelatedField
(
ManyRelatedField
):
def
to_internal_value
(
self
,
data
):
data
=
json
.
loads
(
data
)
if
isinstance
(
data
,
dict
):
data
=
[
data
]
return
[
self
.
child_relation
.
to_internal_value
(
item
[
'
@id
'
])
for
item
in
data
]
def
to_representation
(
self
,
value
):
return
{
'
@id
'
:
self
.
id
,
'
ldp:contains
'
:
super
().
to_representation
(
value
)}
def
get_attribute
(
self
,
instance
):
self
.
id
=
self
.
parent
.
context
[
'
request
'
].
get_full_path
()
+
self
.
field_name
+
"
/
"
return
super
().
get_attribute
(
instance
)
class
JsonLdRelatedField
(
JsonLdField
):
class
JsonLdRelatedField
(
JsonLdField
):
def
to_representation
(
self
,
value
):
def
to_representation
(
self
,
value
):
try
:
try
:
...
@@ -63,7 +59,7 @@ class JsonLdRelatedField(JsonLdField):
...
@@ -63,7 +59,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
ManyJsonLdRelatedField
(
**
list_kwargs
)
return
ContainerSerializer
(
**
list_kwargs
)
class
JsonLdIdentityField
(
JsonLdField
):
class
JsonLdIdentityField
(
JsonLdField
):
def
__init__
(
self
,
view_name
=
None
,
**
kwargs
):
def
__init__
(
self
,
view_name
=
None
,
**
kwargs
):
...
@@ -90,13 +86,13 @@ class LDPSerializer(HyperlinkedModelSerializer):
...
@@ -90,13 +86,13 @@ class LDPSerializer(HyperlinkedModelSerializer):
return
data
return
data
def
build_nested_field
(
self
,
field_name
,
relation_info
,
nested_depth
):
def
build_nested_field
(
self
,
field_name
,
relation_info
,
nested_depth
):
class
NestedSerializer
(
self
.
__class__
):
class
Nested
LDP
Serializer
(
self
.
__class__
):
class
Meta
:
class
Meta
:
model
=
relation_info
.
related_model
model
=
relation_info
.
related_model
depth
=
nested_depth
-
1
depth
=
nested_depth
-
1
fields
=
'
__all__
'
fields
=
'
__all__
'
return
NestedSerializer
,
get_nested_relation_kwargs
(
relation_info
)
return
Nested
LDP
Serializer
,
get_nested_relation_kwargs
(
relation_info
)
@classmethod
@classmethod
def
many_init
(
cls
,
*
args
,
**
kwargs
):
def
many_init
(
cls
,
*
args
,
**
kwargs
):
...
...
This diff is collapsed.
Click to expand it.
setup.py
+
1
−
1
View file @
4f113112
...
@@ -2,7 +2,7 @@ from setuptools import setup
...
@@ -2,7 +2,7 @@ from setuptools import setup
setup
(
setup
(
name
=
'
djangoldp
'
,
name
=
'
djangoldp
'
,
version
=
'
0.5a
2
'
,
version
=
'
0.5a
4
'
,
url
=
'
https://git.happy-dev.fr/happy-dev/djangoldp/
'
,
url
=
'
https://git.happy-dev.fr/happy-dev/djangoldp/
'
,
author
=
"
Startin
'
blox
"
,
author
=
"
Startin
'
blox
"
,
author_email
=
'
sylvain@happy-dev.fr
'
,
author_email
=
'
sylvain@happy-dev.fr
'
,
...
...
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