Skip to content
Snippets Groups Projects
Commit 4f113112 authored by Sylvain Le Bon's avatar Sylvain Le Bon
Browse files

bugfix: fixed ids of nested containers

parent da4384bf
No related branches found
No related tags found
No related merge requests found
...@@ -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 NestedLDPSerializer(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 NestedLDPSerializer, get_nested_relation_kwargs(relation_info)
@classmethod @classmethod
def many_init(cls, *args, **kwargs): def many_init(cls, *args, **kwargs):
......
...@@ -2,7 +2,7 @@ from setuptools import setup ...@@ -2,7 +2,7 @@ from setuptools import setup
setup( setup(
name='djangoldp', name='djangoldp',
version='0.5a2', version='0.5a4',
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',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment