diff --git a/djangoldp/models.py b/djangoldp/models.py index 3b5433fbc20a6d38293193e3129617e35c96843d..4b9e5a6a95b9471b9eacb177bc34d0e27e9b6688 100644 --- a/djangoldp/models.py +++ b/djangoldp/models.py @@ -23,3 +23,8 @@ class LDNotification(models.Model): object = models.URLField() type = models.CharField(max_length=255) summary = models.TextField() + class Meta: + permissions = ( + ('view_todo', 'Read'), + ('control_todo', 'Control'), + ) diff --git a/djangoldp/serializers.py b/djangoldp/serializers.py index 1135c75c5aea4e24e4c7d14862b9a9934ff48231..68e4d6c7cd549a67d759da2c92556232659fe54e 100644 --- a/djangoldp/serializers.py +++ b/djangoldp/serializers.py @@ -9,8 +9,12 @@ from rest_framework.utils.field_mapping import get_nested_relation_kwargs from guardian.shortcuts import get_perms class ContainerSerializer(ListSerializer): + id='' def to_representation(self, data): - return {'@id': '', 'ldp:contains':super(ContainerSerializer, self).to_representation(data)} + return {'@id': self.id, 'ldp:contains':super(ContainerSerializer, self).to_representation(data)} + def get_attribute(self, instance): + self.id = self.parent.context['request'].get_full_path()+self.field_name+"/" + return super().get_attribute(instance) @property def data(self): return ReturnDict(super(ListSerializer, self).data, serializer=self) @@ -34,6 +38,11 @@ class ManyJsonLdRelatedField(ManyRelatedField): 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): def to_representation(self, value): @@ -44,7 +53,7 @@ class JsonLdRelatedField(JsonLdField): def to_internal_value(self, data): try: - return super().to_internal_value(json.loads(data)['@id']) + return super().to_internal_value(data['@id']) except: return super().to_internal_value(data) diff --git a/djangoldp/views.py b/djangoldp/views.py index 2c611f8a94ab8c9f7e46964b071cbdafd0e3c170..82a6770a2ea70bebcaae7bbd3ea54def7201af9a 100644 --- a/djangoldp/views.py +++ b/djangoldp/views.py @@ -25,7 +25,7 @@ class JSONLDParser(JSONParser): media_type = 'application/ld+json' def parse(self, stream, media_type=None, parser_context=None): data = super(JSONLDParser, self).parse(stream, media_type, parser_context) - return jsonld.compact(data, ctx=data["@context"]) + return jsonld.compact(data, ctx=settings.LDP_RDF_CONTEXT) class NoCSRFAuthentication(SessionAuthentication): def enforce_csrf(self, request): @@ -42,6 +42,9 @@ class WACPermissions(DjangoObjectPermissions): 'DELETE': ['%(app_label)s.delete_%(model_name)s'], } +class AnnonReadOnly(WACPermissions): + authenticated_users_only = False + class LDPViewSetGenerator(ModelViewSet): """An extension of ModelViewSet that generates automatically URLs for the model""" model = None @@ -83,7 +86,7 @@ class LDPViewSetGenerator(ModelViewSet): ] for field in kwargs.get('nested_fields') or cls.nested_fields: - urls.append(url(detail_expr+field+'/', LDPNestedViewSet.nested_urls(field, **kwargs))) + urls.append(url('^'+detail_expr+field+'/', LDPNestedViewSet.nested_urls(field, **kwargs))) return include(urls) @@ -103,7 +106,7 @@ 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': 0, 'extra_fields': self.nested_fields} + meta_args = {'model': self.model, 'extra_kwargs': {'@id': {'lookup_field': lookup_field}}, 'depth': 2, 'extra_fields': self.nested_fields} if self.fields: meta_args['fields'] = self.fields else: @@ -176,6 +179,7 @@ class LDPNestedViewSet(LDPViewSet): related_field = related_field, parent_lookup_field = cls.get_lookup_arg(**kwargs), model_prefix = cls.get_model(**kwargs)._meta.object_name.lower(), + permission_classes = kwargs.get('permission_classes'), lookup_url_kwarg = related_field.related_model._meta.object_name.lower()+'_id') class LDPSourceViewSet(LDPViewSet):