Commit 8470b6f6 authored by Jean-Baptiste's avatar Jean-Baptiste

Merge branch '171-id' into 'master'

Resolve "Update sib:source structure"

Closes #171

See merge request !97
parents a2dcdd7f f46a399d
Pipeline #5240 passed with stage
in 1 minute and 26 seconds
......@@ -141,6 +141,8 @@ class LDPSource(Model):
class Meta:
rdf_type = 'sib:source'
ordering = ('federation',)
container_path = 'sources'
lookup_field = 'federation'
permissions = (
('view_source', 'acl:Read'),
('control_source', 'acl:Control'),
......
......@@ -69,6 +69,8 @@ class LDListMixin:
container_permissions.extend(
Model.get_permissions(parent_model, self.context['request'].user,
['view']))
if self.id == '':
self.id = '{}{}'.format(settings.SITE_URL, Model.resource(parent_model))
return {'@id': self.id,
'@type': 'ldp:Container',
'ldp:contains': super().to_representation(filtered_values),
......@@ -252,6 +254,8 @@ class LDPSerializer(HyperlinkedModelSerializer):
for field in data:
if isinstance(data[field], dict) and '@id' in data[field]:
data[field]['@id'] = data[field]['@id'].format(Model.container_id(obj), str(getattr(obj, slug_field)))
if not '@id' in data:
data['@id'] = '{}{}'.format(settings.SITE_URL, Model.resource(obj))
rdf_type = Model.get_meta(obj, 'rdf_type', None)
rdf_context = Model.get_meta(obj, 'rdf_context', None)
if rdf_type is not None:
......@@ -274,7 +278,7 @@ class LDPSerializer(HyperlinkedModelSerializer):
if isinstance(instance, QuerySet) or isinstance(instance, Model):
try:
model_class = instance.model
except :
except:
model_class = instance.__class__
serializer_generator = LDPViewSet(model=model_class,
lookup_field=Model.get_meta(model_class, 'lookup_field', 'pk'),
......@@ -294,9 +298,11 @@ class LDPSerializer(HyperlinkedModelSerializer):
return {'@id': '{}{}{}/'.format(settings.SITE_URL, '{}{}/', self.source),
'@type': 'ldp:Container',
'ldp:contains': [serializer.to_representation(item) if item is not None else None for item
'ldp:contains': [serializer.to_representation(item) if item is not None else None for
item
in data],
'permissions': Model.get_permissions(self.parent.Meta.model, self.context['request'].user,
'permissions': Model.get_permissions(self.parent.Meta.model,
self.context['request'].user,
['view', 'add'])
}
else:
......
from django.conf import settings
from django.conf.urls import url, include
from djangoldp.tests.models import Skill, JobOffer, Message, Conversation, Dummy
from djangoldp.tests.models import Skill, JobOffer, Message, Conversation, Dummy, Task
from djangoldp.views import LDPViewSet
urlpatterns = [
url(r'^messages/', LDPViewSet.urls(model=Message, permission_classes=[], fields=["@id", "text", "conversation"], nested_fields=['conversation'])),
url(r'^conversations/', LDPViewSet.urls(model=Conversation, nested_fields=["message_set"], permission_classes=())),
url(r'^tasks/', LDPViewSet.urls(model=Task, permission_classes=())),
url(r'^users/', LDPViewSet.urls(model=settings.AUTH_USER_MODEL, permission_classes=[])),
url(r'^dummys/', LDPViewSet.urls(model=Dummy, permission_classes=[], lookup_field='slug',)),
]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment