Skip to content

Commit

Permalink
refactor(apis_metainfo)!: drop Source model
Browse files Browse the repository at this point in the history
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
  • Loading branch information
b1rger committed Oct 4, 2023
1 parent 45e031e commit d51907b
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 55 deletions.
2 changes: 1 addition & 1 deletion apis_core/api_routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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",
),
]
3 changes: 0 additions & 3 deletions apis_core/apis_entities/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,6 @@ <h3>

{% block info-metadata %}
<table class="table table-bordered table-hover">
<tr>
<th>Source</th>
<td>{{ object.source }}</td>
</tr>
<tr>
<th>Collection(s)</th>
<td>
Expand Down
3 changes: 1 addition & 2 deletions apis_core/apis_metainfo/admin.py
Original file line number Diff line number Diff line change
@@ -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)
17 changes: 17 additions & 0 deletions apis_core/apis_metainfo/migrations/0007_delete_source.py
Original file line number Diff line number Diff line change
@@ -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",
),
]
19 changes: 0 additions & 19 deletions apis_core/apis_metainfo/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,25 +108,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."""
Expand Down
12 changes: 1 addition & 11 deletions apis_core/apis_metainfo/serializers.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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"
Expand Down
15 changes: 1 addition & 14 deletions apis_core/apis_metainfo/test_models.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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")
1 change: 0 additions & 1 deletion apis_core/utils/test_caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"apis_metainfo": [
"Collection",
"RootObject",
"Source",
"Uri",
],
"apis_vocabularies": [
Expand Down

0 comments on commit d51907b

Please sign in to comment.