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

Merge branch '171-container' into 'master'

Resolve "Update sib:source structure"

Closes #171

See merge request !98
parents 8470b6f6 d1bdcdca
Pipeline #5262 failed with stage
in 1 minute and 15 seconds
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2019-09-05 15:42
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('djangoldp', '0001_initial'),
]
operations = [
migrations.RemoveField(
model_name='ldpsource',
name='container',
),
migrations.AlterField(
model_name='ldpsource',
name='id',
field=models.URLField(primary_key=True, serialize=False),
),
]
...@@ -135,18 +135,18 @@ class Model(models.Model): ...@@ -135,18 +135,18 @@ class Model(models.Model):
class LDPSource(Model): class LDPSource(Model):
container = models.URLField() id = models.URLField(primary_key=True)
federation = models.CharField(max_length=255) federation = models.CharField(max_length=255)
class Meta: class Meta:
rdf_type = 'sib:source' rdf_type = 'ldp:Container'
ordering = ('federation',) ordering = ('federation',)
container_path = 'sources' container_path = 'sources'
lookup_field = 'federation' lookup_field = 'id'
permissions = ( permissions = (
('view_source', 'acl:Read'), ('view_source', 'acl:Read'),
('control_source', 'acl:Control'), ('control_source', 'acl:Control'),
) )
def __str__(self): def __str__(self):
return "{}: {}".format(self.federation, self.container) return "{}: {}".format(self.federation, self.id)
...@@ -254,8 +254,10 @@ class LDPSerializer(HyperlinkedModelSerializer): ...@@ -254,8 +254,10 @@ 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: if not ('@id' in data or 'id' in data):
data['@id'] = '{}{}'.format(settings.SITE_URL, Model.resource(obj)) data['@id'] = '{}{}'.format(settings.SITE_URL, Model.resource(obj))
if 'id' in data:
data['@id'] = data.pop('id')
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:
......
...@@ -13,6 +13,6 @@ class TestSource(APITestCase): ...@@ -13,6 +13,6 @@ class TestSource(APITestCase):
pass pass
def test_get_resource(self): def test_get_resource(self):
source = LDPSource.objects.create(federation="source_name", container="http://bar.foo/") source = LDPSource.objects.create(federation="source_name", id="http://bar.foo/")
response = self.client.get('/sources/{}/'.format(source.federation), content_type='application/ld+json') response = self.client.get('/sources/{}/'.format(source.federation), content_type='application/ld+json')
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
...@@ -17,7 +17,7 @@ def __clean_path(path): ...@@ -17,7 +17,7 @@ def __clean_path(path):
urlpatterns = [ urlpatterns = [
url(r'^sources/(?P<federation>\w+)/', LDPSourceViewSet.urls(model=LDPSource, fields=['federation', 'container'], url(r'^sources/(?P<federation>\w+)/', LDPSourceViewSet.urls(model=LDPSource, fields=['federation', 'id'],
permission_classes=[LDPPermissions], )), permission_classes=[LDPPermissions], )),
url(r'^\.well-known/webfinger/?$', WebFingerView.as_view()), url(r'^\.well-known/webfinger/?$', WebFingerView.as_view()),
] ]
......
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