From d1bdcdca5d157573be769144e71deceb8e282cd4 Mon Sep 17 00:00:00 2001
From: Jean-Baptiste <bleme@pm.me>
Date: Thu, 5 Sep 2019 18:02:00 +0200
Subject: [PATCH] update: hack to make LDPSources works with LDFlex

---
 .../migrations/0002_auto_20190905_1542.py     | 24 +++++++++++++++++++
 djangoldp/models.py                           |  8 +++----
 djangoldp/serializers.py                      |  4 +++-
 djangoldp/tests/tests_sources.py              |  2 +-
 djangoldp/urls.py                             |  2 +-
 5 files changed, 33 insertions(+), 7 deletions(-)
 create mode 100644 djangoldp/migrations/0002_auto_20190905_1542.py

diff --git a/djangoldp/migrations/0002_auto_20190905_1542.py b/djangoldp/migrations/0002_auto_20190905_1542.py
new file mode 100644
index 00000000..ff3b2dc1
--- /dev/null
+++ b/djangoldp/migrations/0002_auto_20190905_1542.py
@@ -0,0 +1,24 @@
+# -*- 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),
+        ),
+    ]
diff --git a/djangoldp/models.py b/djangoldp/models.py
index 716688ea..73c1c17d 100644
--- a/djangoldp/models.py
+++ b/djangoldp/models.py
@@ -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)
diff --git a/djangoldp/serializers.py b/djangoldp/serializers.py
index c55ad669..28d1d9b2 100644
--- a/djangoldp/serializers.py
+++ b/djangoldp/serializers.py
@@ -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:
diff --git a/djangoldp/tests/tests_sources.py b/djangoldp/tests/tests_sources.py
index 9720db2a..a68327f5 100644
--- a/djangoldp/tests/tests_sources.py
+++ b/djangoldp/tests/tests_sources.py
@@ -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)
diff --git a/djangoldp/urls.py b/djangoldp/urls.py
index 4fd8d7f4..f92a2ab4 100644
--- a/djangoldp/urls.py
+++ b/djangoldp/urls.py
@@ -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()),
 ]
-- 
GitLab