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
fa4d46aa
Commit
fa4d46aa
authored
6 years ago
by
Jean-Baptiste
Browse files
Options
Downloads
Patches
Plain Diff
update: add a many_depth parameter to the view
parent
00743d42
No related branches found
No related tags found
1 merge request
!16
update: add a many_depth parameter to the view
Pipeline
#689
passed
6 years ago
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
djangoldp/serializers.py
+4
-0
4 additions, 0 deletions
djangoldp/serializers.py
djangoldp/views.py
+8
-4
8 additions, 4 deletions
djangoldp/views.py
with
12 additions
and
4 deletions
djangoldp/serializers.py
+
4
−
0
View file @
fa4d46aa
...
...
@@ -155,6 +155,10 @@ class LDPSerializer(HyperlinkedModelSerializer):
@classmethod
def
many_init
(
cls
,
*
args
,
**
kwargs
):
kwargs
[
'
child
'
]
=
cls
()
try
:
cls
.
Meta
.
depth
=
kwargs
[
'
context
'
][
'
view
'
].
many_depth
except
KeyError
:
pass
return
ContainerSerializer
(
*
args
,
**
kwargs
)
def
create
(
self
,
validated_data
):
...
...
This diff is collapsed.
Click to expand it.
djangoldp/views.py
+
8
−
4
View file @
fa4d46aa
...
...
@@ -89,9 +89,10 @@ class LDPViewSet(LDPViewSetGenerator):
"""
An automatically generated viewset that serves models following the Linked Data Platform convention
"""
fields
=
None
exclude
=
None
depth
=
0
depth
=
1
many_depth
=
0
renderer_classes
=
(
JSONLDRenderer
,)
parser_classes
=
(
JSONLDParser
,)
parser_classes
=
(
JSONLDParser
,)
authentication_classes
=
(
NoCSRFAuthentication
,)
def
__init__
(
self
,
**
kwargs
):
...
...
@@ -106,8 +107,10 @@ class LDPViewSet(LDPViewSetGenerator):
def
build_serializer
(
self
):
model_name
=
self
.
model
.
_meta
.
object_name
.
lower
()
lookup_field
=
get_resolver
().
reverse_dict
[
model_name
+
'
-detail
'
][
0
][
0
][
1
][
0
]
meta_args
=
{
'
model
'
:
self
.
model
,
'
extra_kwargs
'
:
{
'
@id
'
:
{
'
lookup_field
'
:
lookup_field
}},
'
depth
'
:
self
.
depth
,
'
extra_fields
'
:
self
.
nested_fields
}
meta_args
=
{
'
model
'
:
self
.
model
,
'
extra_kwargs
'
:
{
'
@id
'
:
{
'
lookup_field
'
:
lookup_field
}},
'
depth
'
:
self
.
depth
,
'
extra_fields
'
:
self
.
nested_fields
}
if
self
.
fields
:
meta_args
[
'
fields
'
]
=
self
.
fields
else
:
...
...
@@ -141,6 +144,7 @@ class LDPViewSet(LDPViewSetGenerator):
response
=
super
().
update
(
request
,
*
args
,
**
kwargs
)
return
response
class
LDPNestedViewSet
(
LDPViewSet
):
"""
A special case of LDPViewSet serving objects of a relation of a given object (e.g. members of a group, or skills of a user)
"""
parent_model
=
None
...
...
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