Commit f46a399d authored by Jean-Baptiste's avatar Jean-Baptiste

update: fix @id on containers

parent a2dcdd7f
Pipeline #5237 passed with stage
in 1 minute and 21 seconds
...@@ -141,6 +141,8 @@ class LDPSource(Model): ...@@ -141,6 +141,8 @@ class LDPSource(Model):
class Meta: class Meta:
rdf_type = 'sib:source' rdf_type = 'sib:source'
ordering = ('federation',) ordering = ('federation',)
container_path = 'sources'
lookup_field = 'federation'
permissions = ( permissions = (
('view_source', 'acl:Read'), ('view_source', 'acl:Read'),
('control_source', 'acl:Control'), ('control_source', 'acl:Control'),
......
...@@ -69,6 +69,8 @@ class LDListMixin: ...@@ -69,6 +69,8 @@ class LDListMixin:
container_permissions.extend( container_permissions.extend(
Model.get_permissions(parent_model, self.context['request'].user, Model.get_permissions(parent_model, self.context['request'].user,
['view'])) ['view']))
if self.id == '':
self.id = '{}{}'.format(settings.SITE_URL, Model.resource(parent_model))
return {'@id': self.id, return {'@id': self.id,
'@type': 'ldp:Container', '@type': 'ldp:Container',
'ldp:contains': super().to_representation(filtered_values), 'ldp:contains': super().to_representation(filtered_values),
...@@ -252,6 +254,8 @@ class LDPSerializer(HyperlinkedModelSerializer): ...@@ -252,6 +254,8 @@ class LDPSerializer(HyperlinkedModelSerializer):
for field in data: for field in data:
if isinstance(data[field], dict) and '@id' in data[field]: 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))) 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_type = Model.get_meta(obj, 'rdf_type', None)
rdf_context = Model.get_meta(obj, 'rdf_context', None) rdf_context = Model.get_meta(obj, 'rdf_context', None)
if rdf_type is not None: if rdf_type is not None:
...@@ -274,7 +278,7 @@ class LDPSerializer(HyperlinkedModelSerializer): ...@@ -274,7 +278,7 @@ class LDPSerializer(HyperlinkedModelSerializer):
if isinstance(instance, QuerySet) or isinstance(instance, Model): if isinstance(instance, QuerySet) or isinstance(instance, Model):
try: try:
model_class = instance.model model_class = instance.model
except : except:
model_class = instance.__class__ model_class = instance.__class__
serializer_generator = LDPViewSet(model=model_class, serializer_generator = LDPViewSet(model=model_class,
lookup_field=Model.get_meta(model_class, 'lookup_field', 'pk'), lookup_field=Model.get_meta(model_class, 'lookup_field', 'pk'),
...@@ -294,9 +298,11 @@ class LDPSerializer(HyperlinkedModelSerializer): ...@@ -294,9 +298,11 @@ class LDPSerializer(HyperlinkedModelSerializer):
return {'@id': '{}{}{}/'.format(settings.SITE_URL, '{}{}/', self.source), return {'@id': '{}{}{}/'.format(settings.SITE_URL, '{}{}/', self.source),
'@type': 'ldp:Container', '@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], 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']) ['view', 'add'])
} }
else: else:
......
from django.conf import settings from django.conf import settings
from django.conf.urls import url, include 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 from djangoldp.views import LDPViewSet
urlpatterns = [ urlpatterns = [
url(r'^messages/', LDPViewSet.urls(model=Message, permission_classes=[], fields=["@id", "text", "conversation"], nested_fields=['conversation'])), 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'^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'^users/', LDPViewSet.urls(model=settings.AUTH_USER_MODEL, permission_classes=[])),
url(r'^dummys/', LDPViewSet.urls(model=Dummy, permission_classes=[], lookup_field='slug',)), 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