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
5404fcce
Commit
5404fcce
authored
6 years ago
by
Jean-Baptiste
Browse files
Options
Downloads
Patches
Plain Diff
syntax: refactor to use Model utilities functions
parent
3908a5e1
No related branches found
No related tags found
1 merge request
!24
Resolve "Get URL of saved resource from its model"
Pipeline
#739
passed
6 years ago
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
djangoldp/serializers.py
+8
-10
8 additions, 10 deletions
djangoldp/serializers.py
with
8 additions
and
10 deletions
djangoldp/serializers.py
+
8
−
10
View file @
5404fcce
...
@@ -16,6 +16,8 @@ from rest_framework.settings import api_settings
...
@@ -16,6 +16,8 @@ from rest_framework.settings import api_settings
from
rest_framework.utils.field_mapping
import
get_nested_relation_kwargs
from
rest_framework.utils.field_mapping
import
get_nested_relation_kwargs
from
rest_framework.utils.serializer_helpers
import
ReturnDict
from
rest_framework.utils.serializer_helpers
import
ReturnDict
from
djangoldp.models
import
Model
class
LDListMixin
:
class
LDListMixin
:
def
to_internal_value
(
self
,
data
):
def
to_internal_value
(
self
,
data
):
...
@@ -40,9 +42,8 @@ class LDListMixin:
...
@@ -40,9 +42,8 @@ class LDListMixin:
def
get_value
(
self
,
dictionary
):
def
get_value
(
self
,
dictionary
):
try
:
try
:
object_list
=
dictionary
[
"
@graph
"
]
object_list
=
dictionary
[
"
@graph
"
]
view_name
=
'
{}-list
'
.
format
(
self
.
parent
.
Meta
.
model
.
_meta
.
object_name
.
lower
())
container_id
=
Model
.
container_id
(
self
.
parent
.
instance
)
part_id
=
'
/{}
'
.
format
(
get_resolver
().
reverse_dict
[
view_name
][
0
][
0
][
0
])
obj
=
next
(
filter
(
lambda
o
:
container_id
in
o
[
'
@id
'
],
object_list
))
obj
=
next
(
filter
(
lambda
o
:
part_id
in
o
[
'
@id
'
],
object_list
))
list
=
super
().
get_value
(
obj
)
list
=
super
().
get_value
(
obj
)
try
:
try
:
list
=
next
(
filter
(
lambda
o
:
list
[
'
@id
'
]
==
o
[
'
@id
'
],
object_list
))
list
=
next
(
filter
(
lambda
o
:
list
[
'
@id
'
]
==
o
[
'
@id
'
],
object_list
))
...
@@ -197,9 +198,8 @@ class LDPSerializer(HyperlinkedModelSerializer):
...
@@ -197,9 +198,8 @@ class LDPSerializer(HyperlinkedModelSerializer):
def
get_value
(
self
,
dictionary
):
def
get_value
(
self
,
dictionary
):
try
:
try
:
object_list
=
dictionary
[
"
@graph
"
]
object_list
=
dictionary
[
"
@graph
"
]
part_id
=
'
/{}
'
.
format
(
get_resolver
().
reverse_dict
[
self
.
parent_view_name
][
0
][
0
][
0
],
resource_id
=
Model
.
resource_id
(
self
.
parent
.
instance
)
self
.
parent
.
instance
.
pk
)
obj
=
next
(
filter
(
lambda
o
:
resource_id
in
o
[
'
@id
'
],
object_list
))
obj
=
next
(
filter
(
lambda
o
:
part_id
in
o
[
'
@id
'
],
object_list
))
return
super
().
get_value
(
obj
)
return
super
().
get_value
(
obj
)
except
KeyError
:
except
KeyError
:
return
super
().
get_value
(
dictionary
)
return
super
().
get_value
(
dictionary
)
...
@@ -288,10 +288,8 @@ class LDPSerializer(HyperlinkedModelSerializer):
...
@@ -288,10 +288,8 @@ class LDPSerializer(HyperlinkedModelSerializer):
def
get_value
(
self
,
dictionary
):
def
get_value
(
self
,
dictionary
):
try
:
try
:
object_list
=
dictionary
[
"
@graph
"
]
object_list
=
dictionary
[
"
@graph
"
]
view_name
=
'
{}-list
'
.
format
(
self
.
parent
.
Meta
.
model
.
_meta
.
object_name
.
lower
())
container_id
=
Model
.
container_path
(
self
.
parent
.
instance
)
part_id
=
'
/{}
'
.
format
(
get_resolver
().
reverse_dict
[
view_name
][
0
][
0
][
0
],
obj
=
next
(
filter
(
lambda
o
:
container_id
in
o
[
self
.
url_field_name
],
object_list
))
self
.
parent
.
instance
.
pk
)
obj
=
next
(
filter
(
lambda
o
:
part_id
in
o
[
self
.
url_field_name
],
object_list
))
item
=
super
().
get_value
(
obj
)
item
=
super
().
get_value
(
obj
)
full_item
=
None
full_item
=
None
if
item
is
empty
:
if
item
is
empty
:
...
...
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