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
c1823ca6
Commit
c1823ca6
authored
7 years ago
by
Sylvain Le Bon
Browse files
Options
Downloads
Patches
Plain Diff
update: configurable fields (fix
#6
)
parent
d3c4d19a
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
serializers.py
+5
-1
5 additions, 1 deletion
serializers.py
views.py
+8
-2
8 additions, 2 deletions
views.py
with
13 additions
and
3 deletions
serializers.py
+
5
−
1
View file @
c1823ca6
from
django.core.exceptions
import
ImproperlyConfigured
from
django.core.urlresolvers
import
get_resolver
from
django.utils.datastructures
import
MultiValueDictKeyError
from
rest_framework.relations
import
HyperlinkedRelatedField
,
ManyRelatedField
...
...
@@ -22,7 +23,10 @@ class JsonLdRelatedField(HyperlinkedRelatedField):
except
MultiValueDictKeyError
:
pass
def
to_representation
(
self
,
value
):
return
{
'
@id
'
:
super
().
to_representation
(
value
)}
try
:
return
{
'
@id
'
:
super
().
to_representation
(
value
)}
except
ImproperlyConfigured
:
return
value
.
pk
class
LDPSerializer
(
HyperlinkedModelSerializer
):
url_field_name
=
"
@id
"
...
...
This diff is collapsed.
Click to expand it.
views.py
+
8
−
2
View file @
c1823ca6
...
...
@@ -28,14 +28,20 @@ class NoCSRFAuthentication(SessionAuthentication):
class
LDPViewSet
(
ModelViewSet
):
model
=
None
fields
=
None
renderer_classes
=
(
JSONLDRenderer
,
)
parser_classes
=
(
JSONLDParser
,
)
authentication_classes
=
(
NoCSRFAuthentication
,)
def
__init__
(
self
,
**
kwargs
):
super
().
__init__
(
**
kwargs
)
class_attrs
=
{
'
Meta
'
:
type
(
'
Meta
'
,
(),
{
'
model
'
:
self
.
model
,
'
exclude
'
:
()})}
self
.
serializer_class
=
type
(
LDPSerializer
)(
self
.
model
.
_meta
.
object_name
.
lower
()
+
'
Serializer
'
,
(
LDPSerializer
,),
class_attrs
)
meta_args
=
{
'
model
'
:
self
.
model
}
if
self
.
fields
:
meta_args
[
'
fields
'
]
=
self
.
fields
else
:
meta_args
[
'
exclude
'
]
=
()
meta_class
=
type
(
'
Meta
'
,
(),
meta_args
)
self
.
serializer_class
=
type
(
LDPSerializer
)(
self
.
model
.
_meta
.
object_name
.
lower
()
+
'
Serializer
'
,
(
LDPSerializer
,),
{
'
Meta
'
:
meta_class
})
def
get_queryset
(
self
,
*
args
,
**
kwargs
):
if
self
.
model
:
...
...
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