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

update: hack to make LDPSources works with LDFlex

parent 8470b6f6
Pipeline #5242 passed with stage
in 1 minute and 21 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):
class LDPSource(Model):
container = models.URLField()
id = models.URLField(primary_key=True)
federation = models.CharField(max_length=255)
class Meta:
rdf_type = 'sib:source'
rdf_type = 'ldp:Container'
ordering = ('federation',)
container_path = 'sources'
lookup_field = 'federation'
lookup_field = 'id'
permissions = (
('view_source', 'acl:Read'),
('control_source', 'acl:Control'),
)
def __str__(self):
return "{}: {}".format(self.federation, self.container)
return "{}: {}".format(self.federation, self.id)
......@@ -254,8 +254,10 @@ 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:
if not ('@id' in data or 'id' in data):
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_context = Model.get_meta(obj, 'rdf_context', None)
if rdf_type is not None:
......
......@@ -13,6 +13,6 @@ class TestSource(APITestCase):
pass
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')
self.assertEqual(response.status_code, 200)
......@@ -17,7 +17,7 @@ def __clean_path(path):
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], )),
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