From 72b4f998eb087fc355022460c8dea03dadc762c5 Mon Sep 17 00:00:00 2001 From: Birger Schacht Date: Thu, 29 Jun 2023 15:35:53 +0200 Subject: [PATCH] feat(apis_metainfo)!: drop `Source` model The `Source` model was introduced to store information about where an entity was imported from. This can easily be replaced by a custom field in the ontology. Therefore the `Source` model was removed. Closes: #227 --- apis_core/api_routers.py | 2 +- .../0003_remove_tempentityclass_source.py | 17 +++++++++++++++++ apis_core/apis_entities/models.py | 3 --- .../detail_views/detail_generic.html | 4 ---- apis_core/apis_metainfo/admin.py | 3 +-- .../migrations/0007_delete_source.py | 17 +++++++++++++++++ apis_core/apis_metainfo/models.py | 19 ------------------- apis_core/apis_metainfo/serializers.py | 12 +----------- apis_core/apis_metainfo/test_models.py | 15 +-------------- apis_core/utils/test_caching.py | 1 - 10 files changed, 38 insertions(+), 55 deletions(-) create mode 100644 apis_core/apis_entities/migrations/0003_remove_tempentityclass_source.py create mode 100644 apis_core/apis_metainfo/migrations/0007_delete_source.py diff --git a/apis_core/api_routers.py b/apis_core/api_routers.py index 821407354..19e069c9c 100644 --- a/apis_core/api_routers.py +++ b/apis_core/api_routers.py @@ -245,7 +245,7 @@ def generic_serializer_creation_factory(): if x in entity_field_name_list: exclude_lst_fin.append(x) if entity_str.lower() == "text": - exclude_lst_fin.extend(["kind", "source"]) + exclude_lst_fin.extend(["kind"]) for f in entity._meta.get_fields(): if f.__class__.__name__ == "ManyToManyField": prefetch_rel.append(f.name) diff --git a/apis_core/apis_entities/migrations/0003_remove_tempentityclass_source.py b/apis_core/apis_entities/migrations/0003_remove_tempentityclass_source.py new file mode 100644 index 000000000..7fb25cf8c --- /dev/null +++ b/apis_core/apis_entities/migrations/0003_remove_tempentityclass_source.py @@ -0,0 +1,17 @@ +# Generated by Django 4.1.10 on 2023-09-21 07:05 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('apis_entities', '0002_remove_tempentityclass_text'), + ] + + operations = [ + migrations.RemoveField( + model_name='tempentityclass', + name='source', + ), + ] diff --git a/apis_core/apis_entities/models.py b/apis_core/apis_entities/models.py index 4b3497bc3..2a30ca87c 100644 --- a/apis_core/apis_entities/models.py +++ b/apis_core/apis_entities/models.py @@ -105,9 +105,6 @@ class TempEntityClass(AbstractEntity): # TODO RDF: Make Text also a Subclass of RootObject collection = models.ManyToManyField("apis_metainfo.Collection") status = models.CharField(max_length=100) - source = models.ForeignKey( - "apis_metainfo.Source", blank=True, null=True, on_delete=models.SET_NULL - ) references = models.TextField(blank=True, null=True) notes = models.TextField(blank=True, null=True) published = models.BooleanField(default=False) diff --git a/apis_core/apis_entities/templates/apis_entities/detail_views/detail_generic.html b/apis_core/apis_entities/templates/apis_entities/detail_views/detail_generic.html index fe11973bd..6f26411a7 100644 --- a/apis_core/apis_entities/templates/apis_entities/detail_views/detail_generic.html +++ b/apis_core/apis_entities/templates/apis_entities/detail_views/detail_generic.html @@ -246,10 +246,6 @@

{% block info-metadata %} - - - -
Source{{ object.source }}
Collection(s) diff --git a/apis_core/apis_metainfo/admin.py b/apis_core/apis_metainfo/admin.py index b91c2a8b8..fe341e121 100644 --- a/apis_core/apis_metainfo/admin.py +++ b/apis_core/apis_metainfo/admin.py @@ -1,7 +1,6 @@ from django.contrib import admin -from .models import Source, Collection, Uri +from .models import Collection, Uri -admin.site.register(Source) admin.site.register(Collection) admin.site.register(Uri) diff --git a/apis_core/apis_metainfo/migrations/0007_delete_source.py b/apis_core/apis_metainfo/migrations/0007_delete_source.py new file mode 100644 index 000000000..58743bbad --- /dev/null +++ b/apis_core/apis_metainfo/migrations/0007_delete_source.py @@ -0,0 +1,17 @@ +# Generated by Django 4.1.10 on 2023-09-21 07:05 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('apis_entities', '0003_remove_tempentityclass_source'), + ('apis_metainfo', '0006_delete_text'), + ] + + operations = [ + migrations.DeleteModel( + name='Source', + ), + ] diff --git a/apis_core/apis_metainfo/models.py b/apis_core/apis_metainfo/models.py index bee4f1ab1..e623733ea 100644 --- a/apis_core/apis_metainfo/models.py +++ b/apis_core/apis_metainfo/models.py @@ -107,25 +107,6 @@ def duplicate(self): return duplicate -@reversion.register() -class Source(models.Model): - """Holds information about entities and their relations""" - - orig_filename = models.CharField(max_length=255, blank=True) - indexed = models.BooleanField(default=False) - pubinfo = models.CharField(max_length=400, blank=True) - author = models.CharField(max_length=255, blank=True) - orig_id = models.PositiveIntegerField(blank=True, null=True) - - def __str__(self): - if self.author != "" and self.orig_filename != "": - return "{}, stored by {}".format(self.orig_filename, self.author) - elif self.orig_filename != "": - return "{}".format(self.orig_filename) - else: - return "(ID: {})".format(self.id) - - @reversion.register() class Collection(models.Model): """Allows to group entities and relation.""" diff --git a/apis_core/apis_metainfo/serializers.py b/apis_core/apis_metainfo/serializers.py index 112847285..6366d6911 100644 --- a/apis_core/apis_metainfo/serializers.py +++ b/apis_core/apis_metainfo/serializers.py @@ -1,7 +1,7 @@ from django.contrib.contenttypes.models import ContentType from rest_framework import serializers -from .models import Collection, Source, Text, Uri +from .models import Collection, Text, Uri from apis_core.apis_entities.models import TempEntityClass @@ -41,16 +41,6 @@ class Meta: model = Text -class SourceSerializer(serializers.HyperlinkedModelSerializer): - url = serializers.HyperlinkedIdentityField( - view_name="apis:apis_api:source-detail", lookup_field="pk" - ) - - class Meta: - fields = "__all__" - model = Source - - class UriSerializer(serializers.HyperlinkedModelSerializer): url = serializers.HyperlinkedIdentityField( view_name="apis:apis_api:uri-detail", lookup_field="pk" diff --git a/apis_core/apis_metainfo/test_models.py b/apis_core/apis_metainfo/test_models.py index 400aa17b4..fc462fef8 100644 --- a/apis_core/apis_metainfo/test_models.py +++ b/apis_core/apis_metainfo/test_models.py @@ -1,7 +1,7 @@ from django.test import TestCase from django.contrib.contenttypes.models import ContentType -from .models import RootObject, Source, Uri +from .models import RootObject, Uri class ModelTestCase(TestCase): @@ -17,19 +17,6 @@ def test_root_object(self): self.assertEquals(str(rfoo), "foo") self.assertEquals(str(rnone), "no name provided") - def test_source(self): - s = Source.objects.create() - s_fname = Source.objects.create(orig_filename="file_name_of_source") - s_fname_aut = Source.objects.create( - orig_filename="file_name_of_source", author="Alice" - ) - self.assertEquals(str(s), f"(ID: {s.id})") - self.assertEquals(str(s_fname), "file_name_of_source") - self.assertEquals( - str(s_fname_aut), - "file_name_of_source, stored by Alice", - ) - def test_uri(self): ufoo = Uri.objects.create() self.assertEquals(str(ufoo), "None") diff --git a/apis_core/utils/test_caching.py b/apis_core/utils/test_caching.py index 8bad33fd1..54b3fa5c5 100644 --- a/apis_core/utils/test_caching.py +++ b/apis_core/utils/test_caching.py @@ -6,7 +6,6 @@ "apis_metainfo": [ "Collection", "RootObject", - "Source", "Uri", ], "apis_vocabularies": [