Skip to content

Commit

Permalink
feat(apis_metainfo): drop Source model
Browse files Browse the repository at this point in the history
  • Loading branch information
b1rger committed Jun 30, 2023
1 parent 7569984 commit e567466
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 56 deletions.
2 changes: 1 addition & 1 deletion apis_core/api_routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,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.8 on 2023-06-29 13:38

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("apis_entities", "0001_initial"),
]

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 @@ -107,9 +107,6 @@ class TempEntityClass(AbstractEntity):
text = models.ManyToManyField("apis_metainfo.Text", blank=True)
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 @@ -246,10 +246,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,8 +1,7 @@
from django.contrib import admin

from .models import Source, Collection, Text, Uri
from .models import Collection, Text, Uri

admin.site.register(Source)
admin.site.register(Collection)
admin.site.register(Text)
admin.site.register(Uri)
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 4.1.8 on 2023-06-29 13:38

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("apis_entities", "0002_remove_tempentityclass_source"),
("apis_metainfo", "0004_auto_20230310_0804"),
]

operations = [
migrations.RemoveField(
model_name="text",
name="source",
),
migrations.DeleteModel(
name="Source",
),
]
20 changes: 0 additions & 20 deletions apis_core/apis_metainfo/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,25 +135,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 Expand Up @@ -199,7 +180,6 @@ class Text(models.Model):

kind = models.ForeignKey(TextType, blank=True, null=True, on_delete=models.SET_NULL)
text = models.TextField(blank=True)
source = models.ForeignKey(Source, blank=True, null=True, on_delete=models.SET_NULL)

def __str__(self):
if self.text != "":
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, UriCandidate
from .models import RootObject, Uri, UriCandidate


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")
Expand Down
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",
"Text",
"Uri",
"UriCandidate",
Expand Down

0 comments on commit e567466

Please sign in to comment.